CreatingCookieEventArgs.IsPersistent Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald die aangeeft of de verificatiecooky buiten de huidige sessie moet worden bewaard.
public:
property bool IsPersistent { bool get(); };
public bool IsPersistent { get; }
member this.IsPersistent : bool
Public ReadOnly Property IsPersistent As Boolean
Waarde van eigenschap
true indien de cookie buiten de huidige sessie moet worden bewaard; anders, false.
Voorbeelden
In het volgende voorbeeld ziet u een gebeurtenis-handler voor de CreatingCookie gebeurtenis. De handler haalt gebruikerswaarden op uit het CreatingCookieEventArgs object om de verificatiecookor aan te passen. De IsPersistent eigenschap van het FormsAuthenticationTicket object is ingesteld op de waarde in de IsPersistent eigenschap.
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
Opmerkingen
Wanneer u een FormsAuthenticationTicket object maakt, kunt u de IsPersistent eigenschap gebruiken om op te geven of de verificatiecooky buiten de huidige sessie wordt bewaard.