views:

175

answers:

2

I would like to know how to set up the routing in asp.net mvc so I can have similar urls to stackoverflows question urls?

http://stackoverflow.com/questions/115634/do-you-believe-that-asp-net-mvc-is-ready-for-production/

I am guessing that for url creation there is a helper class that creates the question urls.

The part i am wondering is how this is implemented on the Controller side. I think that most probably the home controller has a questions action and the id is 115634. Then comes the title of the question - I guess this is for search engine optimization. My problem is how the controller method signature would look like.

Is it a Question(int? id) or Question(string? param) that contains both the id and the title?

How would one implement this?

+5  A: 

Check out this question where Jeff Atwood himself posts the code they use to make the friendly URL. Also, I am not a C# developer so I am not sure how things work on ASP.NET MVC, but if you try and remove the title in a StackOverflow URL, the page works anyways. They are 100% for readability for humans (so they know what to expect when they see the link) and for search engines. As such I would expect if you want something similar you make it an optional param in the controller.

Paolo Bergantino
Actually, search engines are largely smart enough not to care anymore- at least not as much. It's more to make it somewhat human-readable.
Joel Coehoorn
Do you have a source for this? Last I've heard, Google cares quite a bit if a search term matches something in the URL. But yes, they are also for the benefit of humans. Added this.
Paolo Bergantino
http://stackoverflow.com/questions/505793/do-seo-friendly-urls-really-affect-a-pages-ranking
Joel Coehoorn
The answer you refer to currently shows outdated code. Jeff updated his original post with a new version: http://stackoverflow.com/questions/25259/how-do-you-include-a-webpage-title-as-part-of-a-webpage-url/25486#25486
Tom Lokhorst
If Jeff Atwood himself post the code then the that should be the answer! :)
gyurisc
A: 

Hi, check out this question...may be the answer you're looking for (:

Kieron