ASP. net mvc project Separation

Source: Internet
Author: User

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

Related Article

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.