URL Rewriting without 3rd Party Add-Ons

URL Rewriting without 3rd Party Add-Ons

Posted:  March 1, 2012

URL Rewriting without 3rd Party Add-Ons

.Net 3.5 Brought to developers of MVC applications the wonderful world of Page Routing. This allows us .Net developers to not have to worry about SEO friendly URLs (pretty much) any more, as we can simplify the URL rewritting process and get rid of those pesky 3rd party add-ons.

.Net 4 brings this Page Routing to web forms. Which allows the same thing, however, now we do not have to be developing an MVC application in order for it to be utilized.

Yes, there is a little extra code that is necessary to make this all work, however it is well worth the 4-5 lines, of code you can control, over the 3rd party reference with which you have no control over the source code.

You will need to edit your Global.asax file, as well as any other .aspx page that will utilize the routing.

In the case of o7th Web Design’s Site Rendering Engine, here is the code snippet that they use to route all page requests to the only page in the application: /Default.aspx


Imports System.Web.Routing

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Private Sub RegisterRoutes(ByVal Routes As RouteCollection)
With Routes
'Do not Route Existing Files
.RouteExistingFiles = False
'Ignore These
'Re-Route These
End With
End Sub

And to process these requests:


Private _PageLink = Page.RouteData.Values("Page")
Private _APageLink = Page.RouteData.Values("APage")
Private _MPageLink = Page.RouteData.Values("MPage")

More info: http://msdn.microsoft.com/en-us/library/cc668201.aspx

Kevin Pirnie

20+ Years of PC and server maintenance & over 15+ years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.