首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET 2.0 Windows 整合驗證機制深度解析

     編輯:關於ASP.NET

本文詳細闡述 ASP.NET 2.0 中 IIS 整合 Windows 驗證與 ASP.NET Windows 驗證的運作機制,涵蓋 NTLM/Kerberos、WindowsAuthenticationModule、IPrincipal/IIdentity 建構全流程。

核心流程

  1. IIS 完成 Windows 驗證(NTLM/Kerberos),取得用戶存取權杖。
  2. 權杖傳遞給 ASP.NET 執行緒,封裝在 HttpContext.WorkerRequest。
  3. WindowsAuthenticationModule(在 <authentication mode="Windows"/> 時啟用)於 AuthenticateRequest 事件中取出權杖。
  4. 建構 WindowsIdentity → WindowsPrincipal(含角色列表,透過 P/Invoke 取得 Windows 群組)。
  5. 將 WindowsPrincipal 存入 HttpContext.User,供後續授權模組使用。

關鍵組件

  • WindowsAuthenticationModule:核心 HTTP 模組,負責建構 Principal/Identity。
  • DefaultAuthenticationModule:將 Thread.CurrentPrincipal 同步設為 HttpContext.User。
  • HttpContext.User:統一存取點,永不為 null(匿名訪問時為匿名 Principal)。

ASP.NET 管線模型

請求經過 HttpApplication → 多個 HTTP 模組(含驗證模組) → HTTP 處理常式。HttpContext 貫穿生命週期傳遞請求/回應資訊。

配置要點

<authentication mode="Windows" />
<!-- machine.config/web.config 中預設已註冊 WindowsAuthenticationModule -->

無需撰寫任何驗證代碼,即可在頁面透過 User.Identity.Name 取得 DOMAIN\username。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved