經過非託管層複雜處理,最終呼叫 ISAPIRuntime.ProcessRequest 進入 HttpRuntime 大門。ISAPIRuntime 繼承 IISAPIRuntime(可與 COM 互通),暴露 ProcessRequest 方法。
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();
String wrPath = wr.GetAppPathTranslated();
String adPath = HttpRuntime.AppDomainAppPathInternal;
if (adPath == null || StringUtil.EqualsIgnoreCase(wrPath, adPath)) {
HttpRuntime.ProcessRequestNoDemand(wr);
return 0;
} else {
HttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged, ...);
return 1;
}
} catch (Exception e) {
// 錯誤處理、ThreadAbortException 重設、HSE_REQ_DONE_WITH_SESSION 判斷等
throw;
}
}
流程:建立 ISAPIWorkerRequest → 初始化 → 檢查應用程式路徑是否變更(變更則重啟 AppDomain) → 呼叫 HttpRuntime.ProcessRequestNoDemand 進入託管處理管線。異常處理包含 Web 事件記錄、執行緒中止重設、AppDomain 卸載特殊處理。此方法為非託管至託管轉換的關鍵橋樑。