Elango_Thanumalayan
Elango_Thanumalayan

Reputation: 25

Changing the URL Extension

I had developed a Web application in Asp.net. When am using the Application over IIS, the file extension as.aspx is visible. Is it possible to hide it (or) rename it....Thankx in advance.

Upvotes: 0

Views: 217

Answers (2)

Matt Davies
Matt Davies

Reputation: 1269

For .NET Framework 3.5 or earlier, you can accomplish this using routing. Try the following solution:

http://www.codedigest.com/Articles/ASPNET/294_Search_Engine_Friendly_URLs_Using_Routing_in_ASPNet_35.aspx

Upvotes: 0

Matt Davies
Matt Davies

Reputation: 1269

For .NET framework 4.0+, try the following rule in web.config (inside <system.webServer>):

The first will redirect URLs using the old format, to remove the .aspx extensions. You should of course update your links as well - eventually you won't need this.

The second rule rewrites URLs internally to add .aspx behind the scenes.

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

Upvotes: 1

Related Questions