gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:41:59 26 4
gpt4 key购买 nike

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

我在 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。如果我注释掉检查文件的第二个条件,它就可以工作。在条件满足的情况下,它失败了。

最佳答案

因为它在没有 <add input="/favicon.ico" matchType="IsFile" /> 的情况下工作线,那条线对我来说是可疑的。

我不得不猜测这与您的 /favicon.ico 有关路径,如 matchType="IsFile"是正确的。

this link对于更多示例,他们的解决方案是不使用正斜杠 (/),而是使用反斜杠 (\)。

But I must to use not slash (/) in line <add input="{DOCUMENT_ROOT}/{R:1}" matchType="IsDirectory" negate="true" />. I must to use BACKSLASH (). That line is right: <add input="{DOCUMENT_ROOT}{R:1}" matchType="IsDirectory" negate="true" />

关于asp.net-mvc - IIS 重写规则 - 检查静态文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com