如何在asp.net IIS7中隐藏任何页面扩展名(.aspx和.asp以及.php和.html)

时间:2015-01-14 12:08:57

标签: asp.net url rewriting

我要求在我的网站中隐藏任何类型的页面扩展,这些页面扩展已经托管了100多页asp,html和aspx页面。      我想隐藏所有类型页面扩展名。我使用以下代码,只适用于.aspx。不适用于.html& .asp页面扩展名

<rule name="RemoveASPX" enabled="true" stopProcessing="true">
      <match url="(.*)\.aspx" />
      <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="AddASPX" 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}.aspx" />
    </rule>

2 个答案:

答案 0 :(得分:0)

<match url="(.*)\.(aspx|php|html)" />

<action type="Rewrite" url="{R:0}.{R:1}" />

您可以更改匹配元素的正则表达式,使其与其他扩展名匹配。

答案 1 :(得分:0)

您可以(并且应该)使用Asp.NET提供的路由机制,在您的特定情况下使用此处所述的MapPageRoute方法:http://msdn.microsoft.com/en-us/library/vstudio/dd329551%28v=vs.100%29.aspx

您对aspx页面的看法也可以应用于其他类型的页面,例如普通的HTML或旧的asp。