URL Rewriting without 3rd Party Add-Ons

URL Rewriting without 3rd Party Add-Ons

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

Global.asax

Imports System.Web.Routing

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RegisterRoutes(RouteTable.Routes)
End Sub

Private Sub RegisterRoutes(ByVal Routes As RouteCollection)
With Routes
'Do not Route Existing Files
.RouteExistingFiles = False
'Ignore These
.Ignore("images/{*pathInfo}")
.Ignore("scripts/{*pathInfo}")
.Ignore("styles/{*pathInfo}")
'Re-Route These
.MapPageRoute("Ajax-Default-Nav",
"Ajax/{APage}/",
"~/Default.aspx")
.MapPageRoute("Mobile-Default-Nav",
"Mobile/{MPage}/",
"~/Default.aspx")
.MapPageRoute("Non-Mobile",
"{Page}/",
"~/Default.aspx")
End With
End Sub

And to process these requests:

Default.aspx

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

Categories


Let Us Help

Get You Online

Contact Us Today

Important Cookie Information
Our website uses cookies. By continuing to browse the site you are agreeing to our use of cookies. For more details about cookies and their use, please see our Cookie Policy.