ASP .Net MVC One of the coolest things about the ASP .Net MVC framework is how it allows you to extensively control URL routing.  Currently this is a huge benefit over web forms (though Web Forms will be capable of this too with .net 4.0).  I won’t get to deep into what URL Routing is but for the sake of this article, URL Routing is a way to expose SEO friendly and “good looking” URLs that don’t necessarily map to a physical file but don’t require the use of parameters to get to your content.  An example of this can be found on this site.  The url of the last entry is this:

http://chrisrisner.com/Windows-7-IIS-7-5-Site-Failure

However, prior to URL routing, we’d probably have something like this:

http://chrisrisner.com/Blog/Entry?Title=Windows—IIS-7-5-Site-Failure

It’s not horrible but it’s not the best thing for SEO.  However, one part of making a link as SEO friendly as possible is using as few directories as possible.  So instead of having /Blog/Archive/EntryTitle, I’d rather just have http://chrisrisner.com/EntryTitle.  Thankfully, URL Routing allows for this.   Let’s say in my route registrar, I have the following:

   1:  routes.MapRoute(
   2:                  "Blog",                                              // Route name
   3:                  "Blog/{action}/{id}",                           // URL with parameters
   4:                  new { controller = "Blog", action = "Index", id = "" }  // Parameter defaults
   5:              );

This would allow the easy /Blog/Archive/EntryTitle links.  I could then follow that up with this to allow the even more friendly chrisrisner.com/EntryTitle links:

   1:  routes.MapRoute(
   2:                  "BlogEntry",                                              // Route name
   3:                  "{id}",                           // URL with parameters
   4:                  new { controller = "Blog", action = "Archive", id = "" }  // Parameter defaults
   5:              );

Chris Risner


3 Comments

Leave a Comment