程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> MVC系列(3) HttpRuntime詳解分析(下)

MVC系列(3) HttpRuntime詳解分析(下)

編輯:關於ASP.NET

文章內容

話說,經過各種各樣復雜的我們不知道的內部處理,非托管代碼正式開始調用ISPAIRuntime的 ProcessRequest方法了(ISPAIRuntime繼承了IISPAIRuntime接口,該接口可以和COM進行交互,並且暴露了 ProcessRequest接口方法)。至於為什麼要調用這個方法,大叔也不太清楚,找不到微軟相關的資料哦。但大叔確定該方法就是我們進入 HttpRuntime的正式大門,接著看吧。

public int ProcessRequest(IntPtr ecb, int iWRType) {  
      
    IntPtr pHttpCompletion = IntPtr.Zero;  
      
    if (iWRType == WORKER_REQUEST_TYPE_IN_PROC_VERSION_2) {  
      
        pHttpCompletion = ecb;  
      
        ecb = UnsafeNativeMethods.GetEcb(pHttpCompletion);  
      
    }  
      
    ISAPIWorkerRequest wr = null;  
      
    try {  
      
        bool useOOP = (iWRType == WORKER_REQUEST_TYPE_OOP);  
      
        wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);  
      
        wr.Initialize();  
      
       
      
        // check if app path matches (need to restart app domain?)  
      
        String wrPath = wr.GetAppPathTranslated();  
      
        String adPath = HttpRuntime.AppDomainAppPathInternal;  
      
       
      
        if (adPath == null ||  
      
            StringUtil.EqualsIgnoreCase(wrPath, adPath)) {   
      
            HttpRuntime.ProcessRequestNoDemand(wr);  
      
            return 0;  
      
        }  
      
        else {  
      
            // need to restart app domain  
      
            HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged,  
      
                                            SR.GetString(SR.Hosting_Phys_Path_Changed,  
      
                                                                            adPath,  
      
                                                                            wrPath));  
      
            return 1;  
      
        }  
      
    }  
      
    catch(Exception e) {  
      
        try {  
      
            WebBaseEvent.RaiseRuntimeError(e, this);  
      
        } catch {}  
      
       
      
        // Have we called HSE_REQ_DONE_WITH_SESSION?  If so, don't re-throw.  
      
        if (wr != null && wr.Ecb == IntPtr.Zero) {  
      
            if (pHttpCompletion != IntPtr.Zero) {  
      
                UnsafeNativeMethods.SetDoneWithSessionCalled(pHttpCompletion);  
      
            }  
      
            // if this is a thread abort exception, cancel the abort  
      
            if (e is ThreadAbortException) {  
      
                Thread.ResetAbort();  
      
            }  
      
            // IMPORTANT: if this thread is being aborted because of an AppDomain.Unload,  
      
            // the CLR will still throw an AppDomainUnloadedException. The native caller  
      
            // must special case COR_E_APPDOMAINUNLOADED(0x80131014) and not  
      
            // call HSE_REQ_DONE_WITH_SESSION more than once.  
      
            return 0;  
      
        }   
      
        // re-throw if we have not called HSE_REQ_DONE_WITH_SESSION  
      
        throw;  
    }  
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved