How to configure routing for my admin section in ASP.NET MVC?

Usually my urls look like standard: www.example.com/controller/action

Now I want to configure my administration section as follows:

 www.example.com/admin/
 www.example.com/admin/user/list
 www.example.com/admin/content/add
etc.

So the format is: www.example.com/admin/controller/action

I cannot figure out how to configure the routes so that they look like this.

+5
source share
3 answers

You just need to map the new path to the "admin" section, hard-coded at the beginning of the route definition.

, RegisterRoutes Global.asax.cs , ( ):

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

: "admin" .

2: , , .

MVC: URL

+11

, - . , "admin", , , URL-.

"" RESTful . , - , - .

, , :

/content/list (for normal users)
/admin/content/add (for admins)

/content/list (for everyone)
/content/add (for admin, but must be authenticated to work)

/admin/ URL- - ( , - /admin ), - RESTful, , , - , , , .

, URL , .

ASP.NET MVC ( ) ActionFilters. , , .

.

+6

MVC 2 'area', :) ScottGu MVC 2 Preview.

+3

All Articles