自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

淺析ASP.NET MVC生命周期

開發(fā) 后端
本文淺析Asp.net MVC生命周期,一個HTTP請求從IIS移交到Asp.net運(yùn)行時,Asp.net MVC是在什么時機(jī)獲得了控制權(quán)并對請求進(jìn)行處理呢?

我對ASP.NET MVC生命周期還是興趣很濃,于是提出兩個問題:

一個HTTP請求從IIS移交到ASP.NET運(yùn)行時,ASP.NETMVC是在什么時機(jī)獲得了控制權(quán)并對請求進(jìn)行處理呢?處理過程又是怎樣的?

HTTP請求處理過程

以IIS7中ASP.NET MVC生命周期為例,來自MSDN的一張HTTP請求處理過程發(fā)生事件的簡圖,后面我列出了一個完整的事件列表。既然ASP.NET MVC還是以ASP.NET運(yùn)行時為基礎(chǔ)那么它必然要在ASP.NET MVC生命周期中對請求進(jìn)行截獲。***反應(yīng)當(dāng)然是去web.config里面去翻翻,我們可以看到UrlRoutingModule的配置節(jié):

  1. <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.
    Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    /> 

看到這里我們的***個問題實際上已經(jīng)有了答案:時機(jī)是在PostResolveRequestCache和PostMapRequestHandler.

ResolveRequestCache event
Occurs when ASP.NET finishes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler (for example, a page or an XML Web service).

源文檔 >

PostMapRequestHandler event
Occurs when ASP.NET has mapped the current request to the appropriate event handler.

源文檔 >


我們使用VS2008中ASP.NET Mvc模板創(chuàng)建一個Demo完成后續(xù)的討論,當(dāng)我們訪問/Home的時候發(fā)生了什么呢?
1.Request 請求到來
2.IIS 根據(jù)請求特征將處理權(quán)移交給 ASP.NET
3.UrlRoutingModule將當(dāng)前請求在 Route Table中進(jìn)行匹配
4.UrlRoutingModule在RouteCollection中查找Request匹配的RouteHandler,默認(rèn)是MvcRouteHandler MvcRouteHandler 創(chuàng)建 MvcHandler實例.
5.MvcHandler執(zhí)行 ProcessRequest.
6.MvcHandler 使用 IControllerFactory 獲得實現(xiàn)了IController接口的實例,找到對應(yīng)的HomeController
7.根據(jù)Request觸發(fā)HomeController的Index方法
8.Index將執(zhí)行結(jié)果存放在ViewData
9.HomeController的Index方法返回 ActionResult
10.Views/Home/Index.aspx將 ViewData呈現(xiàn)在頁面上
11.Index.aspx執(zhí)行ProcessRequest方法
12.Index.aspx執(zhí)行Render方法 輸出到客戶端

通過閱讀ASP.NET Mvc的源碼,我們可以得到更為詳細(xì)的處理過程,我盡可能的忽略掉枝節(jié),強(qiáng)調(diào)請求處理的流程.我們從Global.asax.cs文件切入。

【編輯推薦】

  1. 使用C#實現(xiàn)ASP.NET控件數(shù)組
  2. 淺析因Session導(dǎo)致的ASP.NET網(wǎng)站性能問題
  3. ASP.NET開發(fā)程序過程中值得注意的兩個地方
  4. 淺談基于URL的權(quán)限控制ASP.NET MVC中的實現(xiàn)
  5. ASP.NET、JSP和PHP究竟哪個好
責(zé)任編輯:佚名 來源: 千家綜合布線網(wǎng)
相關(guān)推薦

2009-07-23 18:14:17

MVC生命周期

2009-02-12 13:16:55

請求生命周期MVCASP.NET

2013-04-07 10:42:56

Asp.Net頁面周期

2009-07-23 10:23:44

2009-07-28 09:46:53

ASP.NET服務(wù)器控

2009-08-04 16:05:15

ASP.NET頁面生命

2009-08-04 16:50:15

ASP.NET頁面生命

2009-07-31 10:47:18

ASP.NET頁面生命

2010-04-02 09:02:02

ASP.NET MVC

2009-07-31 12:43:59

ASP.NET MVC

2009-08-03 14:18:40

ASP.NET編程模型ASP.NET頁面生命

2009-08-10 14:31:46

ASP.NET組件設(shè)計ASP.NET控件生命

2009-08-04 17:49:31

Web Page生命周ASP.NET Pos

2009-07-23 14:31:20

ASP.NET MVC

2012-08-16 09:38:38

ASP.NET

2009-07-23 18:55:17

ASP.NET頁生命周

2011-06-21 10:26:37

2009-08-03 14:37:38

ASP.NET編程模型頁面生命周期

2021-04-26 09:22:07

ASP.NET Cor服務(wù)周期

2009-07-31 17:53:39

ASP.NET線程安全
點贊
收藏

51CTO技術(shù)棧公眾號