我在MvcHandler
裏面看到一個名爲ProcessRequest
的函數,但我無法確定它何時會被調用?什麼時候調用MvcHandler.ProcessRequest方法以及由誰?
什麼時候會調用它以及誰會調用它?
我在MvcHandler
裏面看到一個名爲ProcessRequest
的函數,但我無法確定它何時會被調用?什麼時候調用MvcHandler.ProcessRequest方法以及由誰?
什麼時候會調用它以及誰會調用它?
它被ASP.Net管道調用,作爲其生命週期的一部分以及使用路由時採取的具體步驟。
當mvc路由匹配當前請求時,其MvcRouteHandler
返回將處理請求的IHttpHandler
。在這種情況下,一個MvcHandler
返回:
protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
{
requestContext.HttpContext.SetSessionStateBehavior(GetSessionStateBehavior(requestContext));
return new MvcHandler(requestContext);
}
類MvcHandler
實現IHttpHandler
,這是用來定義處理程序的http請求的ASP的接口。
所有這些都是標準ASP. Net application lifecycle的一部分,其中UrlRoutingModule
找到匹配的路由,得到它的路由處理器,最後是IHttpHandler。這將返回到ASP,稍後將調用ProcessRequest
(您可以將其看作request is processed by the HttpApplication pipeline部分的步驟15)。
PS。有一個非常好的MVC特定的流水線圖here
如果我將UrlRoutingModule調用(Modules [「UrlRoutingModule-4.0」]).GetHandler(Request。 RequestContext的);在Application_BeginRequest事件中,我直接將輸出傳遞給瀏覽器。這裏怎麼來的asp.net知道它得到了HttpHandler對象併發送響應到瀏覽器 –
我不明白你的問題,你試圖手動模擬asp.net做什麼?另外,UrlRoutingModule中沒有GetHandler? –
sry它(模塊[「UrlRoutingModule-4.0」]爲UrlRoutingModule).RouteHandler.GetHandler(Request.RequestContext); –
獲得HttpContextBase後,將調用ProcessRequest()方法的內部版本,並將HttpContextBase參數傳遞給它。然後進一步調用ProcessRequestInit(),它負責從RouteData集合中提取控制器名稱,並請求控制器工廠創建相應的控制器。 http://www.codeproject.com/Articles/595520/MvcRouteHandler-and-MvcHandler-in-ASP-NET-MVC-Fram –
您必須搜索實現IHttpHandler合同的類,因爲它只公開一種方法,即ProcessRequest( )一個。偉大的話題。 –
但是誰會調用該方法並在什麼時間點(我的意思是,在應用程序生命週期中的什麼事件) –