用戶和身份對象

用戶對象實現 IPrincipal 接口,並且表示用戶的安全性上下文,代碼基於此用戶運行。用戶對象包括用戶的身份(作爲包含的 IIdentity 對象)以及用戶所屬的任何角色。

ASP.NET 提供了以下用戶和身份對象實現:

WindowsPrincipalWindowsIdentity 對象代表用 Windows 身份驗證進行驗證的用戶。利用這些對象,角色列表自動從 Windows 組集中獲取,Windows 用戶屬於該組。
GenericPrincipalGenericIdentity 對象代表用 Forms 身份驗證或其他自定義身份驗證機制進行驗證的用戶。利用這些對象,角色列表通常從數據庫中以自定義方式獲取。
FormsIdentityPassportIdentity 對象代表分別用 Forms 和 Passport 身份驗證機制進行驗證的用戶。

下面的表格說明了對於一系列的身份驗證設置,從每個變量獲得的結果身份保持一個 IPrincipal 和/或 IIdentity 對象。在表格中使用了一下縮寫:

HttpContext = HttpContext.Current.User,其中 返回一個 IPrincipal 對象,它包含當前 Web 請求的安全性信息。這是經身份驗證的 Web 客戶端。
WindowsIdentity = WindowsIdentity.GetCurrent(),返回當前執行 Win32 線程的安全性上下文。
Thread = Thread.CurrentPrincipal,返回當前執行 .NET 線程的用戶,該線程在 Win32 線程上運行。

 

IIS 匿名身份驗證

Web.config 設置 變量位置 結果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

-
MACHINE/IUSR_MACHINE
-

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

-
MACHINE/ASPNET
-

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

Name provided by user
MACHINE/IUSR_MACHINE
用戶提供名稱

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity線程

Name provided by user
MACHINE/ASPNET
用戶提供名稱

 

IIS 基本身份驗證

Web.config 設置 變量位置 結果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
域/用戶名
域/用戶名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
MACHINE/ASPNET
域/用戶名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

用戶提供名稱
域/用戶名
用戶提供名稱

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

用戶提供名稱
MACHINE/ASPNET
用戶提供名稱

IIS 簡要身份驗證

Web.config: 變量位置 結果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
域/用戶名
域/用戶名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
MACHINE/ASPNET
域/用戶名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

用戶提供名稱
域/用戶名
用戶提供名稱

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

用戶提供名稱
MACHINE/ASPNET
用戶提供名稱

IIS 集成 Windows

Web.config 設置 變量位置 結果身份
<identity impersonate="true"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
域/用戶名
域/用戶名

<identity impersonate="false"/><authentication mode="Windows" />

HttpContext
WindowsIdentity
線程

域/用戶名
MACHINE/ASPNET
域/用戶名

<identity impersonate="true"/><authentication mode="Forms" />

HttpContext
WindowsIdentity
線程

用戶提供名稱
域/用戶名
用戶提供名稱

<identity impersonate="false"/><authentication mode="Forms" />

HttpContext.WindowsIdentity
線程

用戶提供名稱
MACHINE/ASPNET
用戶提供名稱

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章