WindowsAuthenticationEventHandler 代理人

定義

代表處理 WindowsAuthenticationModuleWindowsAuthentication_OnAuthenticate 事件的方法。

public delegate void WindowsAuthenticationEventHandler(System::Object ^ sender, WindowsAuthenticationEventArgs ^ e);
public delegate void WindowsAuthenticationEventHandler(object sender, WindowsAuthenticationEventArgs e);
type WindowsAuthenticationEventHandler = delegate of obj * WindowsAuthenticationEventArgs -> unit
Public Delegate Sub WindowsAuthenticationEventHandler(sender As Object, e As WindowsAuthenticationEventArgs)

參數

sender
Object

事件的來源。

範例

下列程式碼範例會使用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

備註

委派 WindowsAuthenticationEventHandler 是針對 Authenticate 類別的 WindowsAuthenticationModule 事件所定義。 您可以在 ASP.NET 應用程式的 Global.asax 檔案中指定名為WindowsAuthentication_OnAuthenticate的副程式,以存取 AuthenticateWindowsAuthenticationModule 類別的事件。 事件 Authenticate 會在事件期間 AuthenticateRequest 引發。

WindowsAuthenticationModule 使用 IIS 和目前 HttpContext 提供的 Windows 身分識別來建構 WindowsAuthenticationEventArgs 物件,並將它傳遞給WindowsAuthentication_OnAuthenticate事件。

您可以使用 User 提供給WindowsAuthentication_OnAuthenticate事件之 WindowsAuthenticationEventArgs 物件的 屬性,將目前 HttpContext 的 屬性設定 User 為自訂 IPrincipal 物件。 如果您在WindowsAuthentication_OnAuthenticate事件期間未指定 屬性的值 User ,IIS 所提供的 Windows 身分識別會當做目前要求的身分識別使用。 如果 IIS 使用匿名驗證,則 Identity 物件的 WindowsAuthenticationEventArgs 屬性會設定為 方法所傳回的 GetAnonymous 身分識別。

只有在驗證 Mode 設定為 Windows ,而且 WindowsAuthenticationModule 是應用程式的使用中 HTTP 模組時,才會引發WindowsAuthentication_OnAuthenticate事件。

擴充方法

GetMethodInfo(Delegate)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱