FormsAuthenticationModule.Authenticate イベント

定義

アプリケーションが現在の要求を認証するときに発生します。

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

イベントの種類

次のコード例では、FormsAuthentication_OnAuthenticate イベントを使用して、現在HttpContextの の プロパティをカスタム Identityを持つ オブジェクトにGenericPrincipal設定Userします。

public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
  if (FormsAuthentication.CookiesSupported)
  {
    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
    {
      try
      {
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(
          Request.Cookies[FormsAuthentication.FormsCookieName].Value);
        
        args.User = new System.Security.Principal.GenericPrincipal(
          new Samples.AspNet.Security.MyFormsIdentity(ticket),
          new string[0]);
      }
      catch (Exception e)
      {
        // Decrypt method failed.
      }
    }
  }
  else
  {
    throw new HttpException("Cookieless Forms Authentication is not " +
                            "supported for this application.");
  }
}
Public Sub FormsAuthentication_OnAuthenticate(sender As Object, _
                                              args As FormsAuthenticationEventArgs)
  If FormsAuthentication.CookiesSupported Then
    If Not Request.Cookies(FormsAuthentication.FormsCookieName) Is Nothing Then
      Try
        Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt( _
          Request.Cookies(FormsAuthentication.FormsCookieName).Value)
        
        args.User = New System.Security.Principal.GenericPrincipal( _
          New Samples.AspNet.Security.MyFormsIdentity(ticket), _
          New String(0) {})
      Catch e As HttpException
        ' Decrypt method failed.
      End Try
    End If
  Else
      Throw New Exception("Cookieless Forms Authentication is not " & _
                            "supported for this application.")
  End If
End Sub

注釈

イベントは Authenticate 、イベント中に発生します AuthenticateRequest

クラスのイベントを Authenticate 処理するには、ASP.NET アプリケーションの FormsAuthenticationModule Global.asax ファイルに FormsAuthentication_OnAuthenticate という名前のサブルーチンを指定します。

FormsAuthentication_OnAuthenticate イベントに指定された プロパティを使用FormsAuthenticationEventArgsUserして、現在HttpContextの プロパティをUserカスタム IPrincipal オブジェクトに設定できます。 FormsAuthentication_OnAuthenticate イベント中に プロパティのUser値を指定しない場合は、フォーム認証チケットによって Cookie または URL で指定された ID が使用されます。

FormsAuthentication_OnAuthenticate イベントは、アプリケーションの構成ファイルの authentication 要素 (ASP.NET 設定スキーマ) 要素で認証モードが にForms設定されFormsAuthenticationModule、 がアプリケーションのアクティブな HTTP モジュールである場合にのみ発生します。

適用対象

こちらもご覧ください