WindowsAuthenticationModule.Authenticate 事件

定義

在應用程式驗證目前要求時發生。

public:
 event System::Web::Security::WindowsAuthenticationEventHandler ^ Authenticate;
public event System.Web.Security.WindowsAuthenticationEventHandler Authenticate;
member this.Authenticate : System.Web.Security.WindowsAuthenticationEventHandler 
Public Custom Event Authenticate As WindowsAuthenticationEventHandler 

事件類型

範例

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

備註

事件 Authenticate 會在 事件期間 AuthenticateRequest 引發。

您可以在 ASP.NET 應用程式的 Global.asax 檔案中指定名為WindowsAuthentication_OnAuthenticate的副程式,以存取 AuthenticateWindowsAuthenticationModule 類別的事件。

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

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

注意

在以整合模式執行的 IIS 7.0 中, Authenticate 啟用 ASP.NET WindowsAuthenticationModule 和 IIS AnonymousAuthenticationModule 模組時,不會引發 的 事件 WindowsAuthenticationModule 。 在此案例中,若要接收驗證通知,請訂閱 AuthenticateRequest 實例的事件 HttpApplication 。 如需整合模式中相容性問題的詳細資訊,請參閱 將 ASP.NET 應用程式從 IIS 6.0 移至 IIS 7.0

適用於

另請參閱