FormsAuthenticationEventHandler 代理人

定義

FormsAuthenticationModuleFormsAuthentication_OnAuthenticate イベントを処理するメソッドを表します。

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

パラメーター

sender
Object

イベントのソース。

e
FormsAuthenticationEventArgs

イベント データを格納している FormsAuthenticationEventArgs

次のコード例では、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

注釈

デリゲートは FormsAuthenticationEventHandler 、 クラスの イベントに Authenticate 対して定義されます FormsAuthenticationModule 。 クラスのイベントに Authenticate アクセスするには、ASP.NET アプリケーションの FormsAuthenticationModule Global.asax ファイルで FormsAuthentication_OnAuthenticate という名前のサブルーチンを指定します。 イベントは Authenticate 、イベント中に発生します AuthenticateRequest

FormsAuthenticationModule、現在HttpContextの をFormsAuthenticationEventArgs使用して オブジェクトを構築し、FormsAuthentication_OnAuthenticate イベントに渡します。

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

FormsAuthentication_OnAuthenticate イベントは、認証Modeが にForms設定されていてFormsAuthenticationModule、 がアプリケーションのアクティブな HTTP モジュールである場合にのみ発生します。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください