FormsAuthenticationEventArgs 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 FormsAuthentication_OnAuthenticate 事件提供数据。 此类不能被继承。
public ref class FormsAuthenticationEventArgs sealed : EventArgs
	public sealed class FormsAuthenticationEventArgs : EventArgs
	type FormsAuthenticationEventArgs = class
    inherit EventArgs
	Public NotInheritable Class FormsAuthenticationEventArgs
Inherits EventArgs
		- 继承
 
示例
下面的代码示例使用 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 中的表单身份验证票证提供的标识。
仅当身份验证Mode设置为 Forms 并且 是应用程序的活动 HTTP 模块时,FormsAuthenticationModule才会引发 FormsAuthentication_OnAuthenticate 事件。
构造函数
| FormsAuthenticationEventArgs(HttpContext) | 
		 初始化 FormsAuthenticationEventArgs 类的新实例。  | 
        	
属性
| Context | 
		 为当前 HTTP 请求获取 HttpContext 对象。  | 
        	
| User | 
		 获取或设置要与当前请求关联的 IPrincipal 对象。  | 
        	
方法
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		 返回表示当前对象的字符串。 (继承自 Object) |