CreatingCookieEventArgs 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 CreatingCookie 事件提供数据。
public ref class CreatingCookieEventArgs : EventArgs
	public class CreatingCookieEventArgs : EventArgs
	type CreatingCookieEventArgs = class
    inherit EventArgs
	Public Class CreatingCookieEventArgs
Inherits EventArgs
		- 继承
 
示例
以下示例显示了 事件的事件处理程序 CreatingCookie 。 处理程序从 CreatingCookieEventArgs 对象中检索用户值以自定义身份验证 Cookie。 处理程序保存身份验证票证中 CustomCredential 属性的值,并将 属性设置为 CookieIsSettrue 以指示已创建身份验证 Cookie。
void AuthenticationService_CreatingCookie(object sender, 
    System.Web.ApplicationServices.CreatingCookieEventArgs e)
{
    FormsAuthenticationTicket ticket = new
          FormsAuthenticationTicket
            (1,
             e.UserName,
             DateTime.Now,
             DateTime.Now.AddMinutes(30),
             e.IsPersistent,
             e.CustomCredential,
             FormsAuthentication.FormsCookiePath);
    string encryptedTicket =
         FormsAuthentication.Encrypt(ticket);
    HttpCookie cookie = new HttpCookie
         (FormsAuthentication.FormsCookieName,
          encryptedTicket);
    cookie.Expires = DateTime.Now.AddMinutes(30);
    HttpContext.Current.Response.Cookies.Add(cookie);
    e.CookieIsSet = true;
}
Sub AuthenticationService_CreatingCookie(ByVal sender As Object, _
                 ByVal e As System.Web.ApplicationServices.CreatingCookieEventArgs)
    Dim ticket As FormsAuthenticationTicket = New _
       FormsAuthenticationTicket _
        (1, _
         e.Username, _
         DateTime.Now, _
         DateTime.Now.AddMinutes(30), _
         e.IsPersistent, _
         e.CustomCredential, _
         FormsAuthentication.FormsCookiePath)
        
    Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
    
    Dim cookie As HttpCookie = New _
        HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
    cookie.Expires = DateTime.Now.AddMinutes(30)
    
    HttpContext.Current.Response.Cookies.Add(cookie)
    e.CookieIsSet = True
End Sub
	注解
类 CreatingCookieEventArgs 向任何 CreatingCookie 事件处理程序提供值。 通过使用此类的属性,可以在创建自定义身份验证 Cookie 时检索用户凭据。
类 AuthenticationService 在 CreatingCookie 对用户凭据进行身份验证后设置身份验证 Cookie 时引发 事件。 类 AuthenticationService 构造 对象 CreatingCookieEventArgs 并将其传递给任何 CreatingCookie 事件处理程序。
通过 UserNamePassword、 和 CustomCredential 属性检索用户凭据。 属性 CustomCredential 可以包含进行身份验证所需的任何自定义值,例如标识号。 属性 IsPersistent 指示是否应在当前会话后保留身份验证 Cookie。 
              CookieIsSet如果创建身份验证 Cookie,请将 属性设置为 true ,以便 AuthenticationService 类不会创建 Cookie。
属性
| CookieIsSet | 
		 获取或设置一个值,该值指示是否已创建身份验证 Cookie。  | 
        	
| CustomCredential | 
		 获取用户提供的其他身份验证值。  | 
        	
| IsPersistent | 
		 获取一个值,该值指示超出当前会话时是否应保留身份验证 Cookie。  | 
        	
| Password | 
		 获取用户的密码。  | 
        	
| UserName | 
		 获取用户的名称。  | 
        	
方法
| Equals(Object) | 
		 确定指定对象是否等于当前对象。 (继承自 Object) | 
        	
| GetHashCode() | 
		 作为默认哈希函数。 (继承自 Object) | 
        	
| GetType() | 
		 获取当前实例的 Type。 (继承自 Object) | 
        	
| MemberwiseClone() | 
		 创建当前 Object 的浅表副本。 (继承自 Object) | 
        	
| ToString() | 
		 返回表示当前对象的字符串。 (继承自 Object) |