MVC Areas Registration Domain FAQ One

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.