ASP.Net MVC Style Extensionless URLs


https://forum.kartris.com/Topic3227.aspx
Print Topic | Close Window

By BORNXenon - Mon 4 Aug 2014
I'm sure I've seen a post on here at some point regarding ASP.Net MVC style extensionless URLs, however, I can't find it!

Well I quite like the extensionless URL feature provided by the MVC routing engine, happily, the same feature can be employed in Web Forms quite easily with a rewrite rule added to the web.config file.

All that you need to do is find the
<system.webserver>
tag within your web.config file and add the following lines:
<rewrite>
<rules>
<rule name="extensionless" stopProcessing="true">
<match url="(.*)\.aspx$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="removeextension" 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>

Enjoy!