IIS URL Rewriting vs URL Routing

asp.netasp.net MvcIisRoutingUrl Rewriting

asp.net Problem Overview


I was planning to use url routing for a Web Forms application. But, after reading some posts, I am not sure if it is an easy approach.

Is it better to use the URL Rewrite module for web forms? But, it is only for IIS7. Initially, there was some buzz that URL routing is totally decoupled from Asp.Net MVC and it could be used for web forms.

Would love to hear any suggestions..

asp.net Solutions


Solution 1 - asp.net

This is the best article I found about this topic: IIS URL Rewriting and ASP.NET routing by Ruslan Yakushev.

IIS URL Rewriting

When a client makes a request to the Web server for a particular URL, the URL-rewriting component analyzes the requested URL and changes it to a different other URL on the same server. The URL-rewriting component runs very early in the request processing pipeline, so is able to modify the requested URL before the Web server makes a decision about which handler to use for processing the request.

IIS URL Rewriting

ASP.NET Routing

ASP.NET routing is implemented as a managed-code module that plugs into the IIS request processing pipeline at the Resolve Cache stage (PostResolveRequestCache event) and at the Map Handler stage (PostMapRequestHandler). ASP.NET routing is configured to run for all requests made to the Web application.

IIS URL Routing

Differences between URL rewriting and ASP.NET routing:

  1. URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL-rewriting module does not know anything about what handler will eventually process the rewritten URL. In addition, the actual request handler might not know that the URL has been rewritten.
  2. ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing component knows about handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.

In addition to these conceptual differences, there are some functional differences between IIS URL rewriting and ASP.NET routing:

  1. The IIS URL-rewrite module can be used with any type of Web application, which includes ASP.NET, PHP, ASP, and static files. ASP.NET routing can be used only with .NET Framework-based Web applications.
  2. The IIS URL-rewrite module works the same way regardless of whether integrated or classic IIS pipeline mode is used for the application pool. For ASP.NET routing, it is preferable to use integrated pipeline mode. ASP.NET routing can work in classic mode, but in that case the application URLs must include file extensions or the application must be configured to use "*" handler mapping in IIS.
  3. The URL-rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing works only with URL paths and with the HTTP-Method header.
  4. In addition to rewriting, the URL-rewrite module can perform HTTP redirection, issue custom status codes, and abort requests. ASP.NET routing does not perform those tasks.
  5. The URL-rewrite module is not extensible in its current version. ASP.NET routing is fully extensible and customizable.

Solution 2 - asp.net

There's a great post here about the differences between the two from a member of the IIS team.

One caveat I would advise is that for WebForms, you need to be careful when using Routing. I've written a sample implementation of how you'd use routing with WebForms that addresses these concerns and hopefully helps answer your question.

Solution 3 - asp.net

Do you want formatted urls to be a factory for spawning pages?

or do you want to make the .aspx go away?

rewriting, is for making the .aspx go away, or just to tidy up the url.

Routing, is for looking at a request and determining which object should handle it. They sound similar, phil haack has a few good articles on the subject.

in iis6, isapiRewrite, is very good

Solution 4 - asp.net

I recently just wrote my own rewriting system to make the URLs on my sites look better. Basically, you're going to need to write your own IHttpModule and add it to your web.config to intercept incoming requests. You can then use the HttpContext.Current.RewritePath to change what you're pointing at.

You'll also want to configure your site to use the aspnet_isapi for everything.

You'll discover a lot of little problems along the way like trying to work with pages that use "tails" on them (like for PageMethods), or pathing of page elements and form postbacks, but you'll get through them.

If interested, I can post a link to the code and you can check it out. I've worked a lot of the problems out already so you can read through it as you go. I'm sure there are a lot of other people that have done this as well that might be good resources as well.

Solution 5 - asp.net

You may want to check out my answer to this question: ASP.NET - Building your own routing system. I include some good references to help build your own routing system with either using the url rewriting method or the new routing engine that you can use that came out of the ASP.NET MVC project.

Solution 6 - asp.net

The Dynamic Data project that is available with .Net 3.5 SP1 shows a good example of a url routing implementation.

Solution 7 - asp.net

For URL Rewriting on IIS, IIRF works in IIS5, 6, 7. Free. Easy. Fast. Open Source. Regular expression support.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGulzar NazimView Question on Stackoverflow
Solution 1 - asp.netsplattneView Answer on Stackoverflow
Solution 2 - asp.netHaackedView Answer on Stackoverflow
Solution 3 - asp.netDevelopingChrisView Answer on Stackoverflow
Solution 4 - asp.nethugowareView Answer on Stackoverflow
Solution 5 - asp.netDale RaganView Answer on Stackoverflow
Solution 6 - asp.netNorgeView Answer on Stackoverflow
Solution 7 - asp.netCheesoView Answer on Stackoverflow