WindowsAuthenticationModule 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在啟用 Windows 驗證 (Authentication) 時,設定 ASP.NET 應用程式的使用者識別。 此類別無法獲得繼承。
public ref class WindowsAuthenticationModule sealed : System::Web::IHttpModule
public sealed class WindowsAuthenticationModule : System.Web.IHttpModule
type WindowsAuthenticationModule = class
interface IHttpModule
Public NotInheritable Class WindowsAuthenticationModule
Implements IHttpModule
- 繼承
-
WindowsAuthenticationModule
- 實作
範例
下列程式碼範例會使用WindowsAuthentication_OnAuthenticate事件,將目前 HttpContext 的 屬性設定 User 為自訂 IPrincipal 物件。
public void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs args)
{
if (!args.Identity.IsAnonymous)
{
args.User = new Samples.AspNet.Security.MyPrincipal(args.Identity);
}
}
Public Sub WindowsAuthentication_OnAuthenticate(sender As Object, args As WindowsAuthenticationEventArgs)
If Not args.Identity.IsAnonymous Then
args.User = New Samples.AspNet.Security.MyPrincipal(args.Identity)
End If
End Sub
備註
當驗證 Mode 設定為 Windows 時,會將 WindowsAuthenticationModule 目前 HttpContext 的 屬性設定 User 為 IPrincipal 物件,此物件表示 IIS 為目前要求提供的 Windows 身分識別。 如果 IIS 使用匿名驗證,則 WindowsAuthenticationModule 會使用 方法傳回的 GetAnonymous 身分識別。
WindowsAuthenticationModule會 Authenticate 公開事件,讓您為 User 目前 HttpContext 的 屬性提供自訂 IPrincipal 物件。 您可以在 Authenticate ASP.NET 應用程式的 Global.asax 檔案中指定名為 WindowsAuthentication_OnAuthenticate 的副程式來存取事件。
注意
在 IIS 7.0 中,不支援搭配 WindowsAuthenticationModuleFormsAuthenticationModule 類別使用 類別。 如需整合模式中相容性問題的詳細資訊,請參閱 將 ASP.NET 應用程式從 IIS 6.0 移至 IIS 7.0。
建構函式
WindowsAuthenticationModule() |
建立 WindowsAuthenticationModule 類別的執行個體。 |
方法
Dispose() |
除了記憶體之外,釋放 WindowsAuthenticationModule 使用的所有資源。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
Init(HttpApplication) |
初始化 WindowsAuthenticationModule 物件。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
事件
Authenticate |
在應用程式驗證目前要求時發生。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應