Question

I'm writing a simple news site. I want that the URL will be something like this:

http://domain.com/killing-puts-focus-on-crimes-against-latinos

...instead of the basic Controller-View-ID structure. I do not want something like:

http://domain.com/news/killing-puts-focus-on-crimes-against-latinos

How can I do this?

Thanks.

Was it helpful?

Solution

You will want to define what is know as a Catch All route.

Try something similar to:

        routes.MapRoute(
            "News",                                              
            "{*title}",                           
            new { controller = "News", action = "Index" }  
        );

OTHER TIPS

You need a route that looks something like this:

routes.MapRoute (
   "Article",                                             
   "{title}",                          
   new { controller = "Article", action = "Index", title = "" }  
);

You could use the default value for the controller name (like for HomeController). http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top