c# - Correct Process for Routing with Admin Subsite -


i'm building first asp.net mvc2 site, , i'm trying add /admin area site.

i don't want area visibile main set of users accessible when enter http://intranet/admin

what have newscontroller regular users want admin newscontroller , i'm not sure how setup class hierarchy , folders when add views in correct location.

inside global.asax.cs i've added , routes resolve correctly.

routes.maproute(     "default", // route name     "{controller}/{action}/{id}", // url parameters     new { controller = "home", action = "index", id = urlparameter.optional }, // parameter defaults     new string[] { "intranet.controllers" }  );  routes.maproute(     "admin", // route name     "admin/{controller}/{action}/{id}", // url parameters     new { controller = "admin", action = "index", id = urlparameter.optional }, // parameter defaults        new string[] { "intranet.controllers.admin" }  ); 

and in folder hierarchy i've setup

views/      admin/      news/          ...i want new view go here... 

in controllers

controllers/     admin/         admincontroller.cs         newscontroller.cs (this 1 want administration)     newscontroller.cs (this regular 1 viewing list, specific item etc) 

the problem face when go admin/newscontroller.cs on index , add view tries create @ /news/index.aspx rather /admin/news/index.aspx.

this code admin news controller controllers/admin->add->controller

namespace intranet.controllers.admin {     public class newscontroller : controller     {         public actionresult index()         {             return view();         }     } } 

is there i'm doing incorrectly, or should change when add views being created in /admin/{area} directory.

since you're using mvc2, easiest way solve create actual mvc "area" admin section. right you're doing in default section , using admin folder. if create admin area (under well-known location areas) folder, you'll have adminarearegistration - where you'll configure admin routes. because you'll part of area, first segment of url "/admin" used "area" token. disambiguate controller use , correctly pick controller want. you're folder structure be:

/areas     /admin         /controllers             newscontroller.cs etc. 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -