IIS重写规则 - 检查是否存在静态文件

时间:2014-05-29 15:25:09

标签: asp.net-mvc iis rewrite iis-8

有人可以告诉我如何检查静态文件是否作为重写规则条件存在。

我在IIS8上,我的网络应用程序是它自己的网站。我想添加一个重写规则来检查文件是否存在,如果是,则应用重写。这是我的代码:

<rewrite>
    <rules>
        <rule name="Find static gravatar" stopProcessing="true">
            <match url="^images/animage.png$" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                <add input="{QUERY_STRING}" pattern="i=(.+)" />
                <add input="/favicon.ico" matchType="IsFile" />
            </conditions>
            <action type="Rewrite" url="/Somewhere/Else/images/{C:1}.png" appendQueryString="false" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite>

点击网址/images/animage.png?i=SS

在绝望中,我正在检查我知道的文件 - favicon.ico。如果我注释掉检查文件的第二个条件,它就可以了。条件是,它失败了。

1 个答案:

答案 0 :(得分:1)

因为它没有<add input="/favicon.ico" matchType="IsFile" />行,所以该行对我来说是可疑的。

我必须猜测它与/favicon.ico路径有关,因为matchType="IsFile"是正确的。

有关更多示例,请参阅this link,其解决方案是不使用正斜杠(/),而是使用反斜杠(\)。

  

但我必须在行中使用不斜杠(/)&lt; add input =“{DOCUMENT_ROOT} / {R:1}”matchType =“IsDirectory”negate =“true”/&gt;。我必须使用BACKSLASH()。该行是正确的:&lt; add input =“{DOCUMENT_ROOT} {R:1}”matchType =“IsDirectory”negate =“true”/&gt;

相关问题