четверг, 14 марта 2013 г.

Asp.net MVC. How to get rid of /home/ in url

Assume we want to have an url to the Contacts page like mysite/Contacts instead of mysite/Home/Contacts

First of all open RouteConfig.cs under App_Start folder.

      public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("HomeRemover", "{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // add this
            routes.MapRoute("Home", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
        }
That's all.

Комментариев нет: