GateKiller
GateKiller

Reputation: 75869

ASP.NET URL Rewriting

How do I rewrite a URL in ASP.NET?

I would like users to be able to go to

http://www.website.com/users/smith

instead of

http://www.website.com/?user=smith

Upvotes: 36

Views: 10705

Answers (3)

Sam Saffron
Sam Saffron

Reputation: 131092

Microsoft now ships an official URL Rewriting Module for IIS: http://www.iis.net/download/urlrewrite

It supports most types of rewriting including setting server variables and wildcards.

It also will exist on all Azure web instances out of the box.

Upvotes: 5

Nick Berardi
Nick Berardi

Reputation: 54854

Try the Managed Fusion Url Rewriter and Reverse Proxy:

http://urlrewriter.codeplex.com

The rule for rewriting this would be:

# clean up old rules and forward to new URL
RewriteRule ^/?user=(.*)  /users/$1 [NC,R=301]

# rewrite the rule internally
RewriteRule ^/users/(.*)  /?user=$1 [NC,L]

Upvotes: 25

Justin Wignall
Justin Wignall

Reputation:

I have used an httpmodule for url rewriting from www.urlrewriting.net with great success (albeit I believe a much earlier, simpler version)

If you have very few actual rewriting rules then url mappings built in to .NET 2.0 are probably an easier option, there are a few write ups of these on the web, the 4guysfromrolla one seems fairly exhaustive but as you can see they don't support regular expression mappings are are as such rendered fairly useless in a dynamic environment (assuming "smith" in your example is not a special case then these would be of no use)

Upvotes: 4

Related Questions