views:

4333

answers:

7

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..

+6  A: 

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

DevelopingChris
Original ideas: no file extns, search engine friendly, hackable urls. I like the idea of spawning new pages too. :)
Gulzar
good points. yeah catching up on phil haacks posts..
Gulzar
i like isapirewrite but we are trying to avoid 3rd party as much as we can..not my decision..
Gulzar
I agree whole heartedly, on less 3rd party, the catch is, "as much as we can" and iis 7 is usually harder to sell, than a dll for iis 6 boxes, at least with my clients
DevelopingChris
A: 

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

Norge
Is there a URL which gives a good overview or example of this?
pearcewg
+2  A: 

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.

Dale Ragan
+3  A: 

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.

Hugoware
+14  A: 

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.

Haacked
got some good ideas from your posts already. Thank you so much..
Gulzar
I think you got the "Famous person" vote, Phil.
Atømix
+19  A: 

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.
splattne
A: 

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

Cheeso