Learn more about the difference between ASP. NET MVC and WebForm

Source: Internet
Author: User
Tags what is asp
on the difference between ASP. NET MVC and WebForm

Using the ASP. NET MVC framework to create a default project, the first intuitive feeling is that the address is rewrite. A little analysis of the source code and configuration files is not difficult to see, MVC used httpmodules to intercept address requests, specifically used in the System.Web.Routing class library (MVC2, MVC1 How to use the forgotten. While this part of the class library is packaged in. NET Framework3.5 SP1, MVC2 need SP1 support and take it for granted. The System.Web.Routing class library provided by SP1 can easily intercept address requests and is also excellent for encoding processing. UrlRoutingModule class intercept request, before this, Application_Start, will give routetable the global object an intercept setting. This setting is saved with the RouteCollection object, and MVC expands the class--routecollectionextensions. These can not be considered, next, when the user accesses the page, the UrlRoutingModule class intercepts the request, in the routetable to see if the rule, if compliant, will call Mvchandler, this call in the HttpHandlers configuration node is registered, The condition is that the address conforms to the "*.mvc" rule. The Mvchandler ProcessRequest method invokes the controller to execute. In fact, the whole process is a black box, the user can not feel. After a method executes in the controller, it returns the result and then enters the specific ASPX page.

By analyzing the work engineering of MVC, we can compare the difference between it and WebForm. We know that the MVC pattern of the business is placed in the controller to execute, and the ASPX page is only responsible for the display. The actual execution time of the business in MVC is then advanced to Httpmolde, and WebForm's request is only executed in the HttpHandler container. That is, the separation of controller and view in MVC is separated by the ASP. NET request pipeline, so that the logical hierarchy of code is separated without compromising efficiency (one request, while Response.Redirect is two requests).

The advantages of MVC work are obvious, more conducive to understanding the layered logic, to grasp the sense of hierarchy of code. The process between the controller and the ASPX page has been isolated by the framework. As for the controller or view page and model call process, still need to grasp. Asp. NET's MVC framework implements the individual management of the controller code.

While looking at the WebForm development model, it only executes in the HttpHandler container, layering it, lacks support in large areas, and can only rely on logical separation. is not inseparable, but by certain limitations. The interception of HttpHandler is related to the access suffix name. When a page is requested, it is a handler, and the WebForm model realizes the display and logic separation, only then is the WinForm event driver. Obviously, the event must be registered to the page, such as button1_click code. The Page_Load method is executed before Button1_Click executes.

If the display code is written to the Page_Load method, it will result in the need to write additional scrap code, such as if (! Page.IsPostBack) such a decision. The part that needs to be displayed after Button1_Click execution is more difficult to deal with, and another method must be called in the button1_click. The alternative solution is to use Response.Redirect to process the logic in one ASPX page and jump to another displayed page when it's done. The downside to this is that the data is difficult to share on two pages, and jumps are implemented by tagging 302来, so one more request. In addition, through Server.execute,server.transfer or Context.rewritepath, the two page conversion is done on the server side, can share the data, and the MVC framework is handled in a similar way, the disadvantage is the need to manually configure these heavy The newly oriented property.

From the above analysis, we can see that the MVC framework has a strong superiority, and webform is not useless, it is easier to develop in simple application. WebForm is also a layered approach that can be implemented in the same way as MVC, but requires more code to be written when processing. And I think the biggest problem with WebForm development layering is the problem of transferring data between pages and pages, and mastering the use of server-side jump in the WebForm application skills (Server.execute,server.transfer or context.rewritepath) to develop can solve the data transmission problems, ASP. MVC compares with WebForm, WebForm is easier to understand, does not produce complex configurations, and is a good choice.

"Recommended"

1. What is ASP. NET MVC? Summarizing ASP. NET MVC

2. Detailed description of the ASP (mvc--Controller)

3. Detailed description of the ASP. mvc--View

4. Detailed description of ASP. mvc--Routing

5. Code examples for developing custom menu editing tools with ASP.

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.