Can I catch the whole route on the following route?

I have a default that vs .net creates in an MVC application:

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

      

I also want to catch this route (any text after the domain name, but it cannot contain / in it. Ie no folders, just "files" in the root).

www.example.com/blah

      

+1


source to share


1 answer


This route will also match the url www.example.com/blah

, it will use a controller blah

with an action Index

.

If you want to create a specific route for blah

, you can also do this:

routes.MapRoute("BlahRoute",
    "blah/{action}/{id}",
    new { controller = "YourControllerForBlah", action = "Index", id = "" }
);

      



Just make sure that this route is added before the default, as otherwise the default route will match first.

You can check out ASP.NET MVC Storefront Part 7 for some ideas for routing, as well as the ASP.NET Routing Debugger from Phil Haack.

0


source







All Articles