Introduction
This article mainly demonstrates how to deploy multiple ASP. net mvc projects to an IIS Site. It mainly uses the regional functions provided by ASP. net mvc.
ASP. net mvc provides the area function, which can easily divide regions for large websites. So that our project will not be too complex and lead to management confusion. With a region, the pages of each module can be conveniently managed in the corresponding region. With the complexity of the project, the module developed by each developer may also be a complete solution. The UI project to be developed is only a region of the main site project, if you put all the UI projects in one UI project, it is not very convenient for the team to develop, and the effect we want to achieve is: each module corresponds to a UI project. net MVC project]. At last, the sub-project is configured as a region, and the total project is a site.
I. Project Creation
First, create a master ASP. net mvc project, and then create a sub-Asp. . Net MVC project. The project structure is as follows:
Note:
1. areasdemo [subproject, as an area for the main project] And mvcappmain [main web project] are common ASP. NET mvc3 projects.
2. mvccontrollers is a class library project.
3. Supplement: Asp. net MVC Controller: the controller can be placed in any DLL of the site. When searching for the Controller, it searches for all the DLL files under the site. When the class meets the condition: not a static class, when the class name ends with the Controller and implements the condition of the controller base class [actually the most important is the icontroller interface], it will be recognized as the controller. So we can put the Controller in any other project, only by copying the DLL of this controller to the bin directory of the main site or the corresponding dll Directory. Of course, it can also be placed under the Controller folder in the default web project.
2. Add the tested controller and action
Add an action to the areasdemo project of the sub-region web project, and then add a corresponding view.
Add a homecontroller and the corresponding index. cshtml view file to the mvcappmain of the main web project.
Add an admin region to the mvcappmain project for testing.
The project is:
We can see that after an admin region is added to the main site, an areas folder is created by default, and the page for storing regional projects is internal.
3. Add the areas registry class to the sub-project
Open the areasdemo project and add an areasdemoregistration file.CodeAs follows:
Public Class Areasdemoregistration: arearegistration // Register at the primary site
{
Public Override String Areaname
{
Get { Return " Areasdemo " ;}
}
Public Override Void Registerarea (arearegistrationcontext context)
{
Context. maproute (
" Areasdemo_default " , // Route name, which must be unique
" Areasdemo/{controller}/{action}/{ID} " , // Routing rules
New {Action = " Index " , Id = urlparameter. optional} // Default Value
);
}
}
It is actually a common class that implements the arearegistration base class. Then, we register the region route and execute the route table registered to the master site in the application_start event Method of Global. asax. Details
Refer to the red code section in global. asax:
Protected VoidApplication_start ()
{
Arearegistration. registerallareas ();//Register all regions
Registerglobalfilters (globalfilters. filters );
Registerroutes (routetable. routes );
}
At this point, we have completed the basic test work. The following is the deployment phase.
4. Deploy our project
First, we need to reference the subitem to the main project. Then we release the main project to a disk folder. Then, copy the views folder of the sub-project areasdemo to the areas \ areasdemo folder corresponding to the published folder of the main project. Here, areasdemo is areaname, which needs to be manually created. Then, check whether areasdemo. dll Dynamic Link Library [web sub-project] is in the released bin directory ].
Then, we will publish this folder as a website in IIS. The final demonstration result is:
Note: This is the default inde page of the main web.
Note: This is the admin region added to the main site.
Note: This is the page returned by the subproject action request.
Summary
We use ASP.. Net MVC region function implements multiple ASP. the net MVC project is deployed on an IIS Site, so that we can develop multiple projects without being limited to one web project. PossibleArticleThe description is not detailed enough. Please refer to the source code and site folders I mentioned in this article for reference.
Try it now ....
Download: the source code in this article and the folder for deploying the web site
Please indicate the source for reprinting. Thank you.
ASP. NET mvc3 simple getting started Season 1 [index stickers] first recognized ASP. NET mvc2.0 first recognized ASP. NET mvc2.0 [continued]
ASP. NET mvc2.0 URL routing entry-instance
ASP. NET mvc2.0 URL routing entry
Introduction to ASP. NET mvc3 (I) Environment preparations
ASP. NET mvc3 introduction to the ASP. NET mvc3 Project (II)
ASP. NET mvc3 simple getting started Season 1 (3) Introduction to filter in Controller
ASP. NET mvc3 simple getting started Season 1 (4) Detailed description of request processing pipeline
First recognized ASP. NET mvc2.0 first recognized ASP. NET mvc2.0 [continued]
ASP. NET mvc2.0 URL routing entry-instance
ASP. NET mvc2.0 URL routing entry
Introduction to ASP. NET mvc3 (I) Environment preparations
ASP. NET mvc3 introduction to the ASP. NET mvc3 Project (II)
ASP. NET mvc3 simple getting started Season 1 (3) Introduction to filter in Controller
ASP. NET mvc3 simple getting started Season 1 (4) Detailed description of request processing pipeline