简体   繁体   中英

How to Hide any page extension like (.aspx and .asp and .php and .html) in asp.net IIS7

I have a requirement to hide any type of page extension in my site which have hosted 100 more page asp,html and aspx pages. I want to hide all type page extension . I use following code which only works for .aspx. not work on .html & .asp page extension

<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>
<match url="(.*)\.(aspx|php|html)" />

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

You can change regex of the match element so it matches on the other extensions.

You can (and should) use the routing mechanism provided by Asp.NET, in your specific case the MapPageRoute method as described here: http://msdn.microsoft.com/en-us/library/vstudio/dd329551%28v=vs.100%29.aspx

What you see about aspx pages can be applied to other kind of pages too, like plain html or old asp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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