MVC3 Putting news article titles in links

fusioninternet
fusioninternet used Ask the Experts™
on
Hi Experts,

I have a site with news articles and we want to be able to link to these news articles using the following format

http://www.website.com/news/24/this-is-the-news-today

Currently the news is served using this example address http://www.website.com/news/24

What i thought would be the way to do this was to use global.asax.cs and add a maproute that processes the url to ignore the additional text and just use the normal controller action and id.

Unfortunately for me i've got no experience in routes or url re-writing and Im open to suggestions if there is a more efficient way of doing what i want to achieve.

A couple of other examples doing similar to what I want to do are below

Regards
Steve

www.telegraph.co.uk%2Ftechnology%2Fsamsung%2F8684333%2FSamsung-Galaxy-Tab-10.1-hands-on.html

www.ndtv.com%2Farticle%2Fworld%2Flava-rivers-flow-out-of-hawaii-volcano-124607
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
routes.MapRoute("NewsRoute",
               "News/{id}/{title}",
               new { controller = "News", action = "Details", id="",title="" });

Open in new window


Put this Above the 'Default" route in the global.asax

More:
http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_an_mvc_application
http://www.asp.net/mvc/tutorials/creating-custom-routes-cs

Author

Commented:
Worked a treat, thanks very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial