Aracılığıyla paylaş


CreatingCookieEventArgs.CookieIsSet Özellik

Tanım

Kimlik doğrulama tanımlama bilgisinin oluşturulup oluşturulmadığını belirten bir değer alır veya ayarlar.

public:
 property bool CookieIsSet { bool get(); void set(bool value); };
public bool CookieIsSet { get; set; }
member this.CookieIsSet : bool with get, set
Public Property CookieIsSet As Boolean

Özellik Değeri

true kimlik doğrulama tanımlama bilgisi oluşturulduysa; aksi takdirde , false.

Örnekler

Aşağıdaki örnekte olay için bir olay işleyicisi gösterilmektedir CreatingCookie . İşleyici, kimlik doğrulama tanımlama bilgisini özelleştirmek için nesneden CreatingCookieEventArgs kullanıcı değerlerini alır. CookieIsSet özelliği, kimlik doğrulama bileti oluşturulduktan sonra olarak ayarlanırtrue.

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

Açıklamalar

sınıfı, AuthenticationService kimlik doğrulama tanımlama bilgisinin CookieIsSet oluşturulup oluşturulmadığını belirlemek için özelliğini denetler. Olay için CreatingCookie bir olay işleyicisinde kimlik doğrulama tanımlama bilgisi oluşturursanız bu değeri true olarak ayarlarsınız. olarak ayarlanırsa CookieIsSetfalse (varsayılan değer), AuthenticationService sınıfı bir kimlik doğrulama tanımlama bilgisi oluşturur, Bu, olay işleyicisinde oluşturduğunuz tüm tanımlama bilgisinin CreatingCookie üzerine yazar.

Şunlara uygulanır

Ayrıca bkz.