views:

178

answers:

1

Hi,

I have the default that vs.net creates in a MVC app:

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 can't contain a / in it i.e. no folders, just 'files' on the root).

www.example.com/blah

A: 

This route will also match to the "www.example.com/blah" url, it will use the "blah" controller with the "Index" action.

If you want to create a specific route for "blah", you can also do that:

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 the ASP.NET MVC Storefront part 7, for some ideas for routing, and also ASP.NET Routing Debugger from Phil Haack.

Gaspar Nagy