繁体   English   中英

删除Web.config中的ASPX FILE扩展名,但如果URL包含句点,则否定重写

[英]Remove ASPX FILE Extention in Web.config But Negate Rewrite if URL Contains Period

好的,所以到目前为止,我们大多数人可能都使用下面的标准规则来删除网址中的aspx扩展名。

<rule name="Remove">
      <!--Removes the .aspx extension for all pages.-->
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="{R:1}.aspx" />
    </rule>

但是,我想修改规则以防止写入规则捕获带有句点的任何URL。

这样,如果有人尝试输入http://www.domain.com/picture.jpg,该规则将无法捕获。

幸运的是,IsFile和IsDirectory条件可以防止实际文件受到规则的攻击,但是每当我遇到有人键入服务器上不存在的文件时,规则就会捕获该文件,而asp.net会执行以下操作:

http://www.domain.com/404error.aspx?aspxerrorpath=/picture.jpg.aspx

希望没有找到文件时不通过规则。

基本上,我只需要能够添加一个条件,该条件会在域名后的网址中找到句点时取反。 我假设某种正则表达式将起作用。 我似乎无法正常工作。

我能够提出以下解决方案。

        <rule name="RewriteASPX" stopProcessing="true" enabled="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_FILENAME}.aspx" matchType="IsFile" />
            </conditions>
            <action type="Rewrite" url="{R:1}.aspx" />
        </rule>     

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM