当前位置:网站首页>ASP. Net MVC and asp Net web form

ASP. Net MVC and asp Net web form

2022-06-23 20:55:00 conanma

1 ASP.NET MVC

It is provided by Microsoft MVC Pattern based ASP.NET Web Application development framework .

MVC The modes are :

Model: Domain model Process the logical part of the application data , get data , Processing data

View: View Used to process the pages actually returned to the user

Controller: controller adopt Model Read and process data , adopt View Return the result .

2 ASP.NET Webform

stay ASP.NET A development mode based on event model under the framework , Fast development speed , Easy to use .

3 The difference between the two and their respective advantages and disadvantages

ASP.NET As a Microsoft Web Program development framework ,MVC And Webform It is the development mode in different periods ,

stay ASP.NET Operation processing principle Almost the same .

Webform advantage : Can be developed based on the event model , similar Winform in , All requests use ViewState And page lifecycle to maintain control state , At the same time, control development , Speed up development , whole Webform The internal packaging of is relatively high .

Webform shortcoming : Because of the high degree of encapsulation ,Webform Very difficult to expand , It is convenient for developers to understand the internal operation principle , Not easy to test . Concurrent control ViewState Increase the transmission volume of the website server , To some extent, it will affect the efficiency of the program .

MVC advantage : extensible , Easy to unit test , Easy test driven development .MVC The existence of a route in , You can do some pseudo static processing of links .

summary : MVC Instead of Webform, Both are applicable to different development environments , They are the development framework of the presentation layer in the simple three layers , All are ASP.NET Development mode under the framework .

1 Page processing flow : MCV The page processing flow of is still ASP.NET There are extensions on the original ,MVC Through a specific IHttpModule and IHttpHandler To process requests , And Webform Different ,Webform Each of them aspx Every page will have a IHttphandler example .MVC in Controller All than yes IHttpHandler Subclass instances of ,Action Is in MvcHandler Pass through MVC The factory reflection of ,MvcHandler You can customize .

2 Context Request object : Context Session Request Response Cookie Almost the same

3 The configuration files are basically the same , But it's not universal

4 Some server controls are not disabled MVC Use in

5 stay ASP.NET MVC in , Include Membership,healthMonitoring,httpModule,trace Built in and custom component modules are still available .

The appended drawings :MVC Schematic diagram and introduction

123123123.jpg

1 The client sends a request to IIS(mvc Is the integration mode ), perform HttpRunTime Of ProcessRequest Method

2  Created a batch of MvcApplication object , Stored in the application pool , Execute the first MvcApplication In the object instance  Application Of Application_Start() Method 、

RouteConfig.RegisterRountes(RouteTable.Routes)--> Register a default routing rule with the routing rule set 

3   call Application Object instance ProcessRequest Method  , Pass in the context object HttpContext, Start execution 19 Pipeline events 

4  The seventh pipeline event :

    UrlRouting filter :

    1  Get current Reuqest Object RawUrl: here  /Home/Index

    2  To scan the current set of routing rules , Match from top to bottom , The match was successful --{controller}/{action}/{id} This routing rule ,MVC The bottom layer will resolve the controller name according to the routing rules 

    HomeController action:Index

    3  call DefaultControllerFactory Reflection creates an object instance of the controller class , Deposit in RemapHandler in 

    4  take   Controller and action The name is stored as a string RouteData in 

5 The eighth pipeline event

1  Judge the present RemapHandler Is it null,  Not for null Directly skip the pipeline event after execution 

2  by null Continue to create page class objects 

6 The eleventh , Twelve pipeline events

1  Get context RemapHandler Object instance of the controller class in 

2 from RoutData Get the current request from the action name 

3  Execute dynamically in a reflective manner action Method 

4 action The return types are divided into :

    4.1  If it is a view type : Call specific view (.cshtml) Compile into page classes , When calling the Excute() Method , Write all the code to after execution Response in 

    4.2 If it is a non view type , Write the results directly to Response Then you can 
原网站

版权声明
本文为[conanma]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112291149322390.html