ASP. net mvc project Separation
Note:
ZRT. Web is the front-end website directory [D: \ ZRT. Web \]
ZRT. Admin is the background management, directory [D: \ ZRT. Web \ Applications \ Admin \], delete the file [Global. asax]
1. inherit from RazorViewEngine and rewrite the path Template
ZRT. Web. Framework
{
CustomerRazorViewEngine: RazorViewEngine
{
CustomerRazorViewEngine ()
{
AreaViewLocationFormats = []
{
,
};
AreaMasterLocationFormats = []
{
,
};
ViewLocationFormats = []
{
,
};
MasterLocationFormats = []
{
,
};
AreaPartialViewLocationFormats = AreaViewLocationFormats;
PartialViewLocationFormats = ViewLocationFormats;
}
}
} View Code
2. Set the attempt engine in the Global. asax file of ZRT. Web
MvcApplication: System. Web. HttpApplication
{
Application_Start ()
{
AreaRegistration. RegisterAllAreas ();
WebApiConfig. Register (GlobalConfiguration. Configuration );
FilterConfig. RegisterGlobalFilters (GlobalFilters. Filters );
RouteConfig. RegisterRoutes (RouteTable. Routes );
BundleConfig. RegisterBundles (BundleTable. Bundles );
ViewEngines. Engines. Clear ();
ViewEngines. Engines. Add (CustomerRazorViewEngine ());
}
} View Code
3. Modify the route of the default website and add a namespace
RouteConfig
{
RegisterRoutes (RouteCollection routes)
{
Routes. IgnoreRoute ();
Routes. MapRoute (
Name :,
Url :,
Defaults: {controller =, action =, id = UrlParameter. Optional },
Namespaces: [] {}
);
}
} View Code
4. in the registration area, add a class to the ZRT. Admin project. AdminAreaRegistration inherits AreaRegistration.
ZRT. Admin
{
AdminAreaRegistration: AreaRegistration
{
AreaName
{
{
;
}
}
RegisterArea (AreaRegistrationContext context)
{
Context. MapRoute (
,
,
{Controller =, action =, area =, id = },
[] {}
);
}
}
} View Code
5. Modify the ZRT. Admin project Views directory _ ViewStart. cshtml file layout path
;
} View Code
6. Modify the output path of the ZRT. Admin project.
DEMO source code