tags:

views:

86

answers:

2

I was wondering if I could create a routing map with one more higher level than the controller. The typical routing would include "/controller/action/id". What I am looking for is something like "section/controller/action/id" or "controller/section/action/id". How can i do this?

+3  A: 

No problem. Just create a route the URL of which is, for example

path/to/my/application/{controller}/{action}/{id}

...and supply a default controller and action as usual.

A concrete example of this is

context.MapRoute(
    "Admin_default",
    "admin/{controller}/{action}/{id}",
    new { controller = "AdminHome", action = "Index", id = "" }
);

This will map, for example, the following URLs:

/admin/                   => AdminHomeController.Index
/admin/adminhome/         => AdminHomeController.Index
/admin/other/             => OtherController.Index
/admin/statistics/view/50 => StatisticsController.View(50)

Note, though, that if you also have a default route, for example like this:

context.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

...then controller action methods in the Admin routing may also be accessible via this route. Use the URL Routing Debugger to find out for sure.

bzlm
To avoid any confusion, that should be `"pathToApplication/ExtraBits/{controller}/..."` where `pathToApplication` is the root of the IIS Application (i.e. "`~`").
Richard
I figured it out myself. Anyways, thanks for the help.
dattebayo
A: 

Are Areas the answer?

Andrey Shchekin
Areas are orthogonal to this. You can combine this with areas.
bzlm