ASP.NET - creating your own routing system

In a recent project, I built my own MVC infrastructure in PHP. One of the things I implemented is a routing system. I used Apache mod_rewrite to send all requests to index.php, and then parsed the URIs to extract information and route the request.

Now I'm doing ASP.NET, and I'm wondering how and how I can accomplish something like this. Is there a way to redirect all requests (similar to how WordPress does it) to one page where the route’s central processing is done? I know the MVC framework for ASP.NET, but I would like to take a hit on it since I was messing around and learning.

EDIT: BTW, my hosting provider is launching IIS 6

+2
url-rewriting routing
Aug 22 '08 at 16:58
source share
1 answer

This will be a long answer, because I want to make sure that you are fully aware of all the ways to achieve what you want to do.

The routing mechanism that supports the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can use RouteTable and assign routes, as in the ASP.NET MVC application. You just don't get the MVC part on traditional ASP.NET sites. This was a huge improvement for the ASP.NET Framework, and it was great to see that they reused this code and made it work in both frameworks. If you want to know more about this, check out the ScottGu post and scroll down to improve URL routing. There's also a link on how to use System.Web.Routing in WebForms by Phil Haack.

Now, if you still want to write your own. You will need to learn the ASP.NET HTTP pipeline and how to implement IHttpModule and IHttpHandler in order to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key to writing your own routing mechanism. To help put these interfaces into a working example, I could not recommend this article β€œWhat Url Rewriter Are You Using For ASP.Net? ” Right here on SO.

+6
Aug 22 '08 at 17:31
source share



All Articles