FormsAuthenticationEventArgs 类

定义

为 FormsAuthentication_OnAuthenticate 事件提供数据。 此类不能被继承。

public ref class FormsAuthenticationEventArgs sealed : EventArgs
public sealed class FormsAuthenticationEventArgs : EventArgs
type FormsAuthenticationEventArgs = class
    inherit EventArgs
Public NotInheritable Class FormsAuthenticationEventArgs
Inherits EventArgs
继承
FormsAuthenticationEventArgs

示例

下面的代码示例使用 FormsAuthentication_OnAuthenticate 事件将当前HttpContextGenericPrincipal属性设置为User具有自定义Identity的对象。

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

注解

FormsAuthenticationEventArgs 类用于向 FormsAuthentication_OnAuthenticate 事件提供事件值,并使你能够指定当前请求的自定义标识。

FormsAuthenticationModule函数使用当前HttpContext构造对象FormsAuthenticationEventArgs,并将其传递给 FormsAuthentication_OnAuthenticate 事件。

可以使用该User属性将当前HttpContext对象的属性设置为User自定义IPrincipal对象。

如果在 FormsAuthentication_OnAuthenticate 事件期间未为User属性指定值,则使用 Cookie 或 URL 中的表单身份验证票证提供的标识。

The FormsAuthentication_OnAuthenticate event is only raised when the authentication Mode is set to Forms and the FormsAuthenticationModule is an active HTTP module for the application.

构造函数

FormsAuthenticationEventArgs(HttpContext)

初始化 FormsAuthenticationEventArgs 类的新实例。

属性

Context

为当前 HTTP 请求获取 HttpContext 对象。

User

获取或设置要与当前请求关联的 IPrincipal 对象。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅