BKJIA 《ASP. net mvc video tutorial"
Differences between ASP. net mvc and WebForm
Use the ASP. net mvc framework to create default projects. The first intuitive feeling is that the addresses are all rewritten. Through a slight Analysis of the source code and configuration file, it is not difficult to see that MVC uses httpModules to intercept address requests. Specifically, it uses the System. Web. Routing class library MVC2, and how MVC1 is used is forgotten .) This category library is encapsulated in. NET Framework3.5 SP1, and MVC2 requires SP1 support. The System. Web. Routing class library provided by SP1 can easily intercept address requests, and it is also excellent in coding. The UrlRoutingModule class intercepts requests. Before that, during Application_Start, a blocking setting is provided for the global objects of RouteTable. This setting is saved using the RouteCollection object. MVC extends the class-RouteCollectionExtensions. These can be ignored. Next, when the user accesses the page, the UrlRoutingModule class intercepts the request and checks whether the request complies with the rule in RouteTable. If yes, MvcHandler is called, this call is registered on the httpHandlers configuration node, provided that the address meets the "*. mvc rules. The ProcessRequest method of MvcHandler calls the Controller for execution. As a matter of fact, the whole process is black box, and users cannot feel it. After executing a method in the Controller, return the result and go to the specific aspx page.
After analyzing the MVC work project, we can compare it with WebForm. We know that the MVC-mode business is placed in the Controller for execution, while the aspx page is only responsible for display. Therefore, the actual service execution time in MVC is advanced to HttpMolde, while the WebForm request is only executed in the httpHandler container. That is to say, ASP is used for the separation of Controller and View in MVC. the Net request pipeline is isolated, so it will undoubtedly not affect the efficiency of a request, and Response. redirect is a secondary request.
Figure 1 MVC Working Model
The advantages of MVC work are obvious, which is more conducive to understanding the layered logic and grasping the Code's attention. The process from the Controller to the aspx page has been isolated by the framework. As for the calling process of the Controller, View page, and Model, you still need to be sure. ASP. net mvc framework implements separate management of Controller code.
Looking at the WebForm development model, it is only executed in the HttpHandler container and layered. It lacks support in big aspects and can only be logically separated. It does not mean that they cannot be separated, but by some limitations. The interception of HttpHandler is related to the access suffix. When a page is requested, it is a Handler, And the WebForm model achieves display and logic separation, only the WinForm event-driven. Obviously, events must be registered to pages, such as code such as button#click. The Page_Load method is executed before the button#click operation.
The display code is written into the Page_Load method, which causes additional waste code to be written, such as if (! Page. IsPostBack. The part to be displayed after the execution of the button#click operation is more difficult to handle. Writing another method is also required to be called in the button#click operation. The alternative solution is to use Response. Redirect to process the logic on An aspx page. After the processing, the page jumps to another displayed page. The disadvantage of this is that it is difficult to share data between two pages, and the jump is achieved by marking 302, so one more request. In addition, you can also use Server. execute, Server. transfer or Context. if the RewritePath processing method is used, the two page transformations are completed on the server side and data can be shared. It can be said that the processing method of the two pages is similar to that of the MVC framework. The disadvantage is that you need to manually configure these retargeting attributes.
From the above analysis, we can see that the MVC framework has a strong advantage, and WebForm is not useless, and it is easier to develop in simple applications. WebForm can also be implemented in the same way as MVC, but it only needs to write more code during processing. In my opinion, the biggest problem encountered when using WebForm to develop layers is the data transmission between pages. In my opinion, I have mastered the application skills Server that uses Server redirection in WebForm. execute, Server. transfer or Context. to solve the data transmission problem, ASP. compared with WebForm, net mvc is easier to understand and does not produce complicated configurations. It is also a good choice.
Here is the difference between ASP. net mvc and WebForm.
This article is from Birdshover's blog garden article "the biggest difference between MVC and WebForm"
- ASP. net mvc unit test: confusing the Path attribute of the HttpContext class
- Custom ControllerFactory: interface implementation, supporting Area
- ASP. NET Routing
- Add custom routes for ASP. net mvc applications
- Learning how to use ASP. net mvc Routing