Is it possible to create "uncontrolled" URLs with ASP.NET MVC?

I am using ASP.NET MVC 4, .NET 4.5. In any case, in addition to creating separate controllers for each "action", have "uncontrolled" URLs?

I mean, there are actions on the Home controller. URLs such as:

  • site.com/Home/About
  • site.com/Home/Contact

to become

  • site.com/About
  • site.com/Contact

but still use the home controller.

+5
source share
1 answer

You can define routes that do not contain a controller name, for example:

routes.MapRoute(
    "About",                                       // Route name
    "About/",                                      // URL with parameters
    new { controller = "Home", action = "About" }  // Parameter defaults
);

routes.MapRoute(
    "Contact",                                       // Route name
    "Contact/",                                      // URL with parameters
    new { controller = "Home", action = "Contact" }  // Parameter defaults
);
+7
source

All Articles