[. NET special supply-Season 3] ASP. net mvc series: Comparison of the operating mechanisms of traditional WebForm websites and MVC websites, mvcwebform

Source: Internet
Author: User

[. NET special supply-Season 3] ASP. net mvc series: Comparison of the operating mechanisms of traditional WebForm websites and MVC websites, mvcwebform

This article compares the traditional WebForm website and MVC website with the 'operating Mechanism 'in a graphical way.

See:


I. Operating Mechanism

When we access a website, what actions are taken by the browser and server?

(This article only provides a simple operation process. If you are interested, find information to study the complex network process .)

 

(1) WebForm website Operating Mechanism

Assume: www.baidu.com/index.aspx

1. Http request (physical address: index. aspx)

① Send a request

The browser sends a request message to the server, which is accepted by the IIS virtual directory. (After configuring IIS, mount the website to the server and accessVirtual directoryTo access the website .)

② Transfer request

After the IIS software on the server receives the request, it submits the request to. NET FrameWork for processing.

③ Create a page Class Object

According to the request address index. aspx, the. NET FrameWork will create the corresponding index_aspx Class Object (Page Object).

The internal mechanism of IIS:

2. Return to the browser

① Forward and reply

The html elements or other content (html + js + css) to be output to the browser through IIS)

② Resolve to graphical interface

The browser parses html code and translates it into a graphical interface.

 

(2) MVC website Operating Mechanism

Assume: www.baidu.com/news/index

1. Http request (Logical Address: news/index)

① Send a request (news/index)

② Transfer request (same as above)

③ CreateClass Object + Method

. NET FrameWork AccordingRoute Configuration, Parse the URL, andCreate news classAnd callUse the index method of the object. Load the View using the View method, and then access index. cshtml under the View folder.

2. Return to the browser (same as above)

 

Ii. Differences

1. Request Method

① WebForm:Index. aspx page

Www.baidu.com/index.aspx

In the user's opinion, the request is for the index. aspx page. In fact, the server is running the class corresponding to index. aspx (the object of the foreground page class). First, call the ProcessRequest method and then call the Page_Load method.

② MVC: class name + method name

Www.baidu.com/news/index

2. Create an object on the server

① WebForm: Page Class Object

The server creates the 'index. aspx 'object of the index. asp foreground page class'

② MVC: Class Object

MVC: Creates a news object and calls the Index method.

. NET FrameWork parses the URL according to the route configuration, creates news class objects, and calls the index method of the object. Load the View using the View method, and then access index. cshtml under the View folder.

3. Value Transfer Method

① WebForm:CodeBehand

Foreground --> background

Front-end pageInheritanceOn the background page, you can<%... %>Method to access the public properties of the website page (strong coupling)

Background --> foreground

IncludeRunat = ServerThe front-end page of the controlVariableThe method exists in the background class for the background call

② MVC:ViewData

Use ViewData as an intermediate class to transmit data between the Controller and View. Advantage: strong type view (will be discussed in subsequent articles ).

 

Iii. Summary

This article compares the differences between traditional WebForm websites and MVC websites from the following aspects: Request Method, creation method, and server creation object.

However, both WebForm and MVC are based on ASP. NET.MPs Queue ModelTwo different development methods.

(The coarse-grained knowledge points in this article will be further discussed in the future)




Differences between aspnet mvc and WebForm

MVC vertically splits the code in the development process from the server to the browser, and the coupling between layers is very low, because it is encapsulated along the underlying development context, therefore, developers can understand the entire process flow. However, MVC has a major drawback, which deviates from the overall software development idea, that is, it cannot be encapsulated or encapsulated, so it cannot be reused. Who has seen components under mvc? Some are just off-the-shelf cases, and then they are modified. Because a component must involve control and display, but the two layers of mvc development are separated. MVC is only suitable for lightweight development, and the mvc mode is rarely used for desktop development. However, web development is lightweight. So far, all web development is lightweight. Because of the limitations of network hardware conditions, it is impossible to implement complex logic without any need. This is why MVC is very suitable for web development.
WebForm is a web development mechanism in front of Microsoft. It horizontally splits the code, and controls and displays are encapsulated together. It encapsulates the code from the developer's logic rather than the actual situation. This is why webform is easy to use. However, this is not conducive to developers' understanding of the underlying program transfer mechanism. In WebForm, view and controller are put together. When WebForm appears, a large number of components are generated, which is invisible in mvc mode. One of Microsoft's experiences is the rapid development of hardware. Code encapsulation improves development efficiency at the expense of operation efficiency, and sacrifices operation efficiency by improving hardware performance. However, Microsoft has made an empirical mistake in webform. This experience is not suitable for network hardware. network hardware should consider compatibility and be the national infrastructure. The flexibility of updating is far worse than that of a single machine. A large number of components cannot bring any advantages to WebForm due to hardware bottlenecks. After several years of development of webform, Microsoft felt that this would not work. When network hardware was developed, it was not known that it was the year of the monkey, so it copied the mature mvc, using Entity Framework to map databases and objects, it is obvious that it serves as the Model in mvc. Control and display through mvc.
The production relationship of webform is more advanced than mvc, but it is not suitable for the current productivity of network facilities. If it is suitable, it may take 10 years. Webform and mvc prove that production relations must be suitable for productivity. Even if they are powerful, Microsoft cannot change objective rules.

Will the aspnet webform be replaced by MVC? It's amazing to put a webform in a space. The server controls are really harmless.

No, the framework used by small systems

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.