views:

124

answers:

1

Hi, Many hosting companies let you define which page will be shown to the user if the user goes to a page that does not exist. If you define some .aspx page then it will execute and be shown.

My question is, why not use this for routing. since I can parse the users URL and then do a server.transfer to the page I want. I checked and there is no redirect sent to the client and the http headers are HTTP/1.1 200 OK.

So, is this a good idea for servers that don't have ASP.NET 3.5 SP1 or if you are not using MVC?

Thanks

+1  A: 

You "can" do that, but why not just create an HttpModule and handle the routing there? That's how most of the URL rewriting systems work (in actuality, it's also how the MVC routing works since global.asax is just a pre-build HttpModule with a few extras).

The big thing with relying on that kind of server handling you describe is that you really aren't in control of it, and it is a hackish mechanism... by that I mean you are taking a function of the web server that has a specific purpose and design and laying a different meaning and function on top of it... which means you now have no built in handling for an actual 404 error. Plus, the mechanism you are contemplating is harder to adapt to your purpose than just using the other options available to you.

Unless you need something special from routing, you should consider using an existing routing component such as Mod-Rewrite or one of the dozen or so other popular URL rewriters that were built before the MVC routing engine was implemented and work fine in older versions of asp.net. There are also numerous tutorials on using HttpModules, HttpHandlers, and various other techniques to do routing in asp.net webform environments.

Stephen M. Redd
Thanks. That was the exact reason I asked this, since it seemed like a hack and I wanted to know if people thought it would be reliable. Could you please tell me which of your recommendations you would suggest for a site hosted on shared hosting (Godaddy in this case). ie, i can't open up IIS manager and do whatever i want...
adinas
Just about any of the HttpModule based solutions are fine and would not require anything special in IIS. Try this one: http://www.urlrewriting.net/149/en/home.html It is farily simple to work with and well documented.
Stephen M. Redd
Thanks. I've spent the past couple of days learning this and it looks good
adinas