[ASP.NET MVC] Create a project and publish a website (2)

1. Create a project

1. First install VS2012, without MVC4.0 reference "Solutions for No MVC Templates in VS New Projects" _Heroin_s Blog-CSDN Blog :

  PS: You can install multiple VS versions on your computer, there is no need to complain that the 2012 version is too low!

2. Create a project:

Pay attention to select C# -> WEB -> and then select ASP.NET MVC4, the project name and location can be set by yourself.

After clicking OK, use an empty template (other templates defined by VS will basically not be used in the future), Razor view engine (provide syntax for the controller to dynamically generate views, similar to JSP)

After confirmation, the project directory is generated as follows:

Let's briefly understand:

1. The web.config file can store some system configurations, such as database connection fields, etc.;

2. Controllers, Models, Views, these three directories are MVC, currently empty;

3. Models are responsible for database operations: data table description (entity class POJO), data operations (DAL, BLL, data business logic and access, etc.);

4. Controllers dynamically generate pages (if necessary) and provide interfaces (routing) for user access;

5. Views are displayed on the user-side page, providing user interface, such as user input, page jump, etc.

Key point: Models and Controllers are operated on the server, using C# language! Views are first generated on the server (using C#), and then transmitted to the browser of the client. At this time, JS (JQUERY) is used to provide the user interface. Therefore, there are both C# and JS on Views! (Of course the carrier is HTML)

It is worth explaining that the new framework pays more attention to solving technical separation, such as the special Views module, which actively specifies the controller to obtain data, and the controller no longer cares about the specific implementation of the page, and only provides the agreed data interface.

The above explanation is my personal understanding, which is generally the case, and it does not have to be true.

Double-click the App_Start directory to open the routing configuration RouteConfig.cs:

 This is the website entry (home page), which is the default route to access the WEB website. Here you can see that it is accessing the Index Action (behavior?) in the Home controller, where id is a parameter. It is understood as: when visiting the WEB website, first run the Index Action of the Home controller (Action is a behavior, which can be understood as a function!)

Obviously, the controller is empty now, so the effect after running is like this: Click Debug on VS2012-"Start execution without debugging, start the default browser:

 Add controller:

Right-click the Controller directory, select "Add"-"Select "Controller", change the default Default to Home (the above route requires Home), be careful not to delete the following Controller

 After clicking Add:

 By default, a function of ActionResult type is added, which is Action, so it can be basically determined that the route adopts the method of Controller + Action + parameters (not required)

run again:

 The reason is that Index returns a View(); this View does not exist and needs to be created!

Right click in Action (this is very important):

 Select Add View:

 Directly select Add to generate a page file:

 At this time run:

 <h2> </h2> is the tag of html (you can check the HTML syntax)

The operation process is relatively simple: visit the WEB website, find the action of index in the Home controller according to the default route configured in RouteConfig.cs, and the action is bound to the specified index.cshtml page, so the specified page is opened.

2. Publish the website

 Right-click the project and select "Publish" in the menu

Select a new configuration:

 The configuration file is named: test, select the simplest file system (recommended), and then select the directory on the machine (the output website directory)

 Default to the last step, click Publish:

The files for this website are generated in the specified directory:

 Copy this directory to the wwwroot of IIS, and publish the IIS website according to the previous introduction:

 Browse the website:

It indicates that the WEB created by VS2012 has been successfully released.

Finally, modify the configuration in the application pool to "enable 32-bit applications"

Reason: The 32-bit system development used by VS2012 does not enable the 32-bit application pool configuration, and there may be a problem that the version of the calling function does not match (64-bit functions cannot be found, etc.) 

Guess you like

Origin blog.csdn.net/yixiaobo2001/article/details/131979800