MVC Site Background separation

Source: Internet
Author: User

1. Create a new Project Testadmin project type choose one and delete it, because here I just need the solution name "project deposited in F-disk F:\TestAdmin"

2, create a new zgj. The WEB's front-page MVC project, which will start off with that casually selected item, ZGJ. Web address F:\TestAdmin\ZGJ. Web"

3, create a zgjadmin background MVC project, put in ZGJ. Web inside "Zgjadmin address F:\TestAdmin\ZGJ. Web\zgjadmin"

4. Rename the project Zgjadmin to ZGJ for aesthetics. Admin and change the assembly name and the default namespace name to Zgj in its properties. Admin

5, in Zgj. Create a new view engine under the Web customerrazorviewengine inherit from Razorviewengine

    Public classCustomerrazorviewengine:razorviewengine { PublicCustomerrazorviewengine () {areaviewlocationformats=New[]                                          {                                              //default                                              "~/zgjadmin/views/{1}/{0}.cshtml",                                               "~/zgjadmin/views/shared/{0}.cshtml"                                          }; Areamasterlocationformats=New[]                                            {                                                //default                                                "~/zgjadmin/views/{1}/{0}.cshtml",                                                 "~/zgjadmin/views/shared/{0}.cshtml"                                            }; Viewlocationformats=New[]                                      {                                            //default                                            "~/views/{1}/{0}.cshtml",                                             "~/views/shared/{0}.cshtml"                                      }; Masterlocationformats=New[]                                        {                                            //default                                            "~/views/{1}/{0}.cshtml",                                             "~/views/shared/{0}.cshtml"                                        }; Areapartialviewlocationformats=Areaviewlocationformats; Partialviewlocationformats=Viewlocationformats; }    }

6, in Zgj. Web global.asax to load the view engine when the site is started

     Public class MvcApplication:System.Web.HttpApplication    {        protectedvoid  Application_Start ()        {            Arearegistration.registerallareas ();            Webapiconfig.register (globalconfiguration.configuration);            Filterconfig.registerglobalfilters (globalfilters.filters);            Routeconfig.registerroutes (routetable.routes);            ViewEngines.Engines.Clear ();            VIEWENGINES.ENGINES.ADD (new  customerrazorviewengine ());        }    }

7, modify the ZGJ. Routeconfig in the Web adds a namespace to the default route

         Public Static voidregisterroutes (routecollection routes) {routes. Ignoreroute ("{Resource}.axd/{*pathinfo}"); Routes. MapRoute (Name:"Default", URL:"{Controller}/{action}/{id}", defaults:New{controller ="Home", action ="Index", id =urlparameter.optional}, namespaces:New[] {"Zgj. Web.controllers" }            ); }

8. Registration area is ZGJ. Add Class Adminarearegistration in Admin inherit from Arearegistration

     Public classadminarearegistration:arearegistration { Public Override stringAreaName {Get            {                return "Admin"; }        }         Public Override voidRegisterarea (AreaRegistrationContext context) {context. MapRoute ("Admin_default",                "Admin/{controller}/{action}/{id}",                New{controller ="Home", action ="Index", area ="Admin", id ="" },                New[] {"Zgj. Admin.controllers" }            ); }    }

9, in Zgj. Add _viewstart.cshtml layout file under Admin's View directory

@{    "~/zgjadmin/views/shared/_layout.cshtml";}

10, in Zgj. Add Shared directory and add _layout.cshtml layout file under Admin's View directory

11, in Zgj. Modify the output directory of the project in the Admin's properties

MVC Site Background separation

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.