Add areas The main purpose is to differentiate between different businesses and avoid the confusion of different businesses under the same controllers, right-click Add Zone on MVC Project I added Hmbolie and pclient two zones
HMbolieAreaRegistration.cs and PClientAreaRegistration.cs are generated by default, and the fourth parameter in the code is the string[] namespaces namespace parameter.namespaceDemo.Areas.HMbolie
Publicclass HMboliearearegistration:arearegistration
{ publicoverridestring areaname { get { return"hmbolie";
} } Public Override voidRegisterarea (AreaRegistrationContext context) {context. MapRoute ("Hmbolie_default", "Hmbolie/{controller}/{action}/{id}", New{action ="Index", id =urlparameter.optional},New string[] {"Demo.Areas.HMbolie.Controllers" } ); } }
}namespace demo.areas.pclient{ publicclass Pclientarearegistration:arearegistration { publicoverridestring AreaName { get { return'pclient' ; } }
Public Override voidRegisterarea (AreaRegistrationContext context) {context. MapRoute ("Pclient_default", "Pclient/{controller}/{action}/{id}", New{action ="Index", id =urlparameter.optional},New string[] {"Demo.Areas.PClient.Controllers" } ); } }}
At this point areas has been created, but run under IIS feel areas does not play a role, in the official website see areas is through the Application_Start () in the global Arearegistration.registerallareas (); To complete the registration, the code is as follows:
/// <SUMMARY> /// Applicationstart /// </summary> protected void Application_Start () { //system.threading.thread.sleep (10000); Arearegistration.registerallareas (); Registerglobalfilters (globalfilters.filters); RegisterRoutes (routetable.routes); }
I am in the start () thread sleep 10s before starting, breakpoint debugging found Arearegistration.registerallareas () HMbolieAreaRegistration.cs and PClientAreaRegistration.cs are not found in the two related areas classes, the code under IIS is the latest deployment, but does not execute?
The workaround is as follows: Delete the IIS cache file
- C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP. NET Files
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP. NET Files
- After I deleted the cache file under temporary ASP. NET files, restart the website and debug the code, everything is loaded as desired.
MVC Areas Registration Domain FAQ One