The difference between the WebForm website and the MVC site operating mechanism

Source: Internet
Author: User
Tags http request iis
His own understanding of MVC is more difficult to learn than WebForm, but performance is better than WebForm, which is more suitable for large projects, higher cost of development, but low coupling, easy maintenance, not too many off-the-shelf controls, and less development efficiency. It's not easy to learn MVC for people who have a foundation for WebForm.

I. Changes in MVC relative to WebForm

1. Using URL routing technology: The URL of a Web program is no longer a pointer to a specific physical page. aspx, but a method that points to a controller. A typical MVC schema for a program whose URL might look like this:

Http://www.mysite.com/Customer/Index

Programs that use this MVC schema do not have to have a file name extension for their URLs. The customer in the above URL is the controller's name. And index is a method name defined by the customer.

2. Web program interface. aspx no longer uses the server-side form:

<asp:form runat= "Server" ></form>

The postback and page life-cycle events associated with the server-side form do not exist either.

3. The view state is no longer in the page. You will not be able to use view state to store program status information under MVC.

4. Server control events that rely on server-side form are no longer available, and developer-familiar button_clicked events are no longer needed under MVC.

Second, the WebForm website and the MVC website Operation mechanism difference

operating mechanism of ①webform website

Let's say we're going to visit a WebForm site now: www.google.com.hk/Default.aspx (just an example). What are the actions our browsers and servers do?

1) First, the browser will send the request message to the destination server.

IIS is configured to know that the Web site is mounted on the server and that we access the Web site by accessing the virtual directory. At this time, the destination host IIS receives a request to access the Default.aspx file under the virtual directory, which is also a very complex process, including requesting a DNS server, locating the destination host IP, and accessing the destination host based on the IP address. Complex network process is not described, interested in their own to find information learning);

2) When the server-side IIS software receives the request, the request is handed over to the. NET framwork for processing;

3). NET Framwork creates an object of the Default_aspx class, which is what we call the Page object. (after the Webfrom site is created and compiled Default.aspx will be compiled into Default_aspx class)

The entire process is still an HTTP request, and the internal mechanism of IIS implements an IHttpHandler interface that implements a Processrequestfang method

This is what MSDN explains.

The ProcessRequest () method will call the Page_Load () method of the corresponding page

1 protected void Page_Load (object sender, EventArgs e)
2         {
3             //Processed business logic or code that accesses the database
4             // HTML or other content to output
5         }


4) Return to browser (including HTML,CSS,JS, etc.)

The process diagram is as follows:

operating mechanism of ②MVC website

Let's say we're going to visit an MVC site now: Www.google.com.hk/FirstPage/Default (just an example). What do our browsers and servers do again?

1) The browser sends request message (Firstpage/default) to the server

2) server-side IIS corresponding request requests

3). NET framwork resolves the URL based on the routing configuration, creates an object of the FirstPage class, and invokes the corresponding default method

1 public actionresult Default ()
2         {
3 
4                 return view ();//Return to view
5         }

4) Then access the default.cshtml under the View folder and return it to the browser (which includes HTML,CSS,JS, etc.)

The diagram of the process is as follows:

This is just a relatively simple process to run. In fact, in the process of a lot of things, such as: Execute Global.asax in the Application_Start () method to complete some initialization work, and so on, will continue to parse in future articles.

The above is the difference between the WebForm website and the MVC website operating mechanism.

So what are the advantages of using MVC more than WebForm?

① The most important thing is. NET programmers will no longer use the Microsoft-encapsulated controls that many people have criticized for their development.

The ②MVC design pattern reduces the coupling between the model, the business and the data, and the view. The idea of using a three-tier architecture for the development of WebForm sites is also to reduce the coupling of data and views;

③ can reuse views, meaning that the same data can be displayed using different views with different icons.

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.