Vanity URLs

By
Dave
Project
Published
15 Apr 2011 11:31
Last Modified
13 Jan 2013 18:15

The category controller currently uses the following URL structure:

http://{domain}/blog/category/{slug1}

It is often useful for URLs to be more concise, for example when adding a caption to a video. In such cases "vanity URLs" are often used. I've updated the blog categories to enable them to support a vanity URL, currently based on the category slug, as follows:

http://{domain}/blog/{slug}

The approach I took was to inject specific entries into the MVC routing table. Clearly this wouldn't be sensible for large numbers of entries, but the number of blog cetegories should be relatively small, and not every category has to have one. An added complication is that whenever I add, update, or delete a category I may need to regenerate the routing table to support adding/removing vanity URLs. I add the enries as follows:

foreach (Category category in new BlogService().ListCategories())
   if (category.VanityUrl)
      routes.MapRoute(category.Slug, category.Slug, new { controller = "Archive", action = "CategoryIndex", name = category.Slug });

Listing 1. Adding vanity URLs to MVC route table

1 A slug is a "friendly" URL (both from an SEO and human-perspective), using characters which do not require HTML-encoding (e.g. dashes instead of spaces)

Comments

By
cvs-pharmacy-greenbelt-md
21 May 2017 07:28
http://safe-shopping-us.com/#price-comparison-viagra - umd pharmacy <a href="http://safe-store-us.com/#kaiser-pleasanton-pharmacy-hours">boots chemist viagra</a> http://safe-shopping-usa.com/#cialis-online-uk - erectile desfunction <a href="http://best-store-usa.com/#cialis-as-needed">2.5 cialis</a> http://safe-store-us.com/#alabama-board-of-pharmacy - how can i buy cialis online <a href="http://safe-store-usa.com/#buying-viagra-without-prescription">ambulatory care pharmacy</a> http://safe-store-us.com/#buy-tadalafil-20mg-price - 50mg viagra <a href="http://best-store-us.com/#correcting-erectile-dysfunction">how to get a viagra prescription online</a>

Add Comment

*
*
*
Captcha
*
*Required