如何从 Web.config (ASP.NET) 中的规则中排除目录

How to Exclude Directories from Rules in Web.config (ASP.NET)

我在 Web.config 中设置了这些规则:

    <rules>
        <rule name="replacedash">
          <match url="(.*)(-)(.*)\.aspx$" />
          <action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
        </rule>
        <rule name="extensionless" stopProcessing="true">
              <match url="(.*)\.aspx$" />
              <action type="Redirect" url="{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="removeextension" enabled="true">
            <match url=".*" negate="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
                </conditions>
                <action type="Rewrite" url="{R:0}" />
        </rule>
    </rules>

我已经将我的网站从普通的 ASP.NET 升级到 ASP.NET MVC,并且我已经编写了这些规则以防搜索引擎中仍然有一些带有 .aspx 扩展名的旧缓存链接;但是,出于充分的原因,我的网络服务器上的一些目录仍然包含 .aspx 文件,我的规则也正在重写这些扩展名。

如何排除这些文件夹继承我的规则?

此处基于以下解决方案:

How to exclude a directory with IIS URL rewriting?

你可以这样做:

<rules>
    <rule name="ignore web forms folder 1" stopProcessing="true">
        <match url="^webformsfolder1/" />
        <action type="None" />
    </rule>
    <rule name="ignore web forms folder 2" stopProcessing="true">
        <match url="^webformsfolder2/" />
        <action type="None" />
    </rule>
    <rule name="ignore web forms folder 3" stopProcessing="true">
        <match url="^webformsfolder3/" />
        <action type="None" />
    </rule>
    <rule name="replacedash">
      <match url="(.*)(-)(.*)\.aspx$" />
      <action type="Redirect" url="{R:1}{R:3}" redirectType="Permanent" />
    </rule>
    <rule name="extensionless" stopProcessing="true">
          <match url="(.*)\.aspx$" />
          <action type="Redirect" url="{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="removeextension" enabled="true">
        <match url=".*" negate="false" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
            </conditions>
            <action type="Rewrite" url="{R:0}" />
    </rule>
</rules>