Web.config URL重写

时间:2014-07-24 21:11:22

标签: c# iis

我想重写所有路径,除了那些是真实文件或真实目录,/api/*~/Default.aspx

这是我到目前为止所做的:

  <rules>
    <rule name="default" patternSyntax="Wildcard">
      <match url="*" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="Default.aspx" />
    </rule>
  </rules>

问题在于它也会将/api/*重写为Default.aspx

2 个答案:

答案 0 :(得分:0)

尝试添加以下条件:

<conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{URL}" negate="true" pattern="(?:\/api)" />
</conditions>

答案 1 :(得分:0)

我明白了。

<rules>
  <rule name="api" stopProcessing="true">
    <match url="(.*api*)" ignoreCase="true" />
    <action type="None" />
  </rule>
  <rule name="default" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" ignoreCase="false" />
    <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="Default.aspx" />
  </rule>
</rules>