Original address: http://www.cnblogs.com/birdshover/archive/2009/08/24/1552614.html
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).
Figure 1 MVC working model
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 WebForm application skills (Server.execute,server.transfer or context.rewritepath) to develop can solve the data transmission problem, with webform development than the MVC framework easier to understand, do not produce complex Miscellaneous configuration, but also a very good choice.
The biggest difference between MVC and WebForm