On the MVC project, right-click New Zone (Areas) ..., the areas folder is automatically generated and a Model+controller+view MVC framework is created under the folder. In the Views folder, the Web. config is automatically generated, and the XxxAreaRegistration.cs file is automatically generated under the parent folder.
The routing rules for the current zone are automatically generated inside the TestAreaRegistration.cs. In order to avoid conflicts between this routing rule and the default routing rule in the app_start below RouteConfig.cs, it is a good idea to add the namespace parameter in two rules:
Add a line below the Application_Start () function of Global.asax: Arearegistration.registerallareas ();
protected void Application_Start () { arearegistration.registerallareas (); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (bundletable.bundles);}
Thus, areas split management is implemented.
However, in a real-world application, the project has authentication. All of the view uses the same layout. So, the problem comes, after entering the window below the area, then click on the _layout menu above, you can see all the links into the area below, just click on the window. For example, the link to log off becomes:
At this point, we need to modify the layout file below the share file shelf.
<Divclass= "Navbar-header"> <Buttontype= "button"class= "Navbar-toggle"Data-toggle= "Collapse"Data-target= ". Navbar-collapse"> <spanclass= "Icon-bar"></span> <spanclass= "Icon-bar"></span> <spanclass= "Icon-bar"></span> </Button>@Html. ActionLink ("Application Name", "Index", "Home", new {area = ""}, new {@class = "Navbar-brand" })</Div><Divclass= "Navbar-collapse collapse"> <ulclass= "Nav navbar-nav"> <Li>@Html. ActionLink ("Home", "Index", "Home",New {area = ' "}, null)</Li> <Li>@Html. ActionLink ("About", "about", "Home",New {area = ' "}, null)</Li> <Li>@Html. ActionLink ("Contact", "contact", "Home",New {area = ' "}, null)</Li>@if (request.isauthenticated && user.isinrole ("Admin")) {<Li>@Html. ActionLink ("Rolesadmin", "Index", "Rolesadmin",New {area = ' "}, null)</Li> <Li>@Html. ActionLink ("Usersadmin", "Index", "Usersadmin",New {area = ' "}, null)</Li> } </ul>@Html. Partial ("_loginpartial")</Div>
With a red underline, the newly added RouteValue.
Decomposition of items with areas in 15.01.29-MVC