Creating a multi-module Web application in C#MVC

Source: Internet
Author: User

When an application has more and more sub-modules, the application becomes larger and more complex, and the application becomes more and more difficult to maintain. If you separate each submodule into a different Web application, the project will be easy to maintain. I'm not good at describing the benefits of this. In short, modules separate, different programmers different modules, do not affect each other, a huge project, if divided into multiple Web applications, it will be easier to maintain.

So, how to put a large web application into several different Web applications.

Directly record the implementation process:

1. First, we create a master project, and other separation projects will pass through this main project as a junction. , we create a Web application, named Mainmoduledemo here, and select the path to be stored;

Here, we choose an empty MVC project

After clicking OK, our directory grows like this

2. Then we add a homecontroller and HomeController under a page index.cshtml, in the page to write something, for testing;

Now, our directory structure, such as:

3. Now we're writing a tag for the page we just created in _layout.cshtml, like

@Html. ActionLink ("Home", "Index", "Home", new {area = ""}, new {@class = "Navbar-brand"})

4, build the solution, run the solution, you can see the following page

The above is the creation of the master project, and next, formally enter the steps to establish the subproject.

5. Right-click our project manimoduledemo-> Add area (English version, is areas),

6. Pop up the New Area Name dialog box, enter the name of our area (this name will be the same as the sub-project you will be new), here we enter Firstchildmodule, click Add, as shown in

Now our directory structure looks like this:

7. Back up a copy of the FirstChildModuleAreaRegistration.cs file under the new zone, and then delete the Firstchildmodule folder (including the Firstchildmodule folder itself) under areas, as

After the directory structure is deleted, the areas folder is empty, as

9. Create the subproject we want to create, right-click Solution, New Project

10, Popup New Project dialog box

Named Firstchildmodule, and just the new zone name is the same (should not need the same, but I did not try, for easy to understand, set the same name), pay attention to the location of the selection, In the areas folder under the main Project Mainmoduledemo project (which is actually the same as the Zone folder we just deleted)

Click OK to select the MVC empty Project

Now the directory structure looks like this:

11, check Mainmoduledemo, click Show All files, you can see, we just new Fristchildmodule project,

12, change the RouteConfig.cs under the Mainmoduledemo item, modify the namespace to Mainmoduledemo.controllers, as

13. Right-click Firstchildmodule-> Properties, Build tab, modify build Path

In fact, this path exactly points to the bin folder of the main project.

14. Create a controller and a page in Firstchildmodule

15, the 7th step back to the file FirstChildModuleAreaRegistration.cs, copied to the Firstchildmodule root directory, the above steps, our directory structure long such

16, modify the FirstChildModuleAreaRegistration.cs, such as

17, in the Mainmoduledemo _layout.cshtml file, add the following link, which is the link created in Firstchildmodule just now

18, build the entire solution, we can see Firstchildmodule generated DLL files, in the bin in Mainmoduledemo, such as

To run the project, you can see the following page

Click on the sub-module homepage, you can jump to the page we just created in Firstchildmodule, explaining that the module was created successfully.

These are all steps for module separation.

Creating a multi-module Web application in C#MVC

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.