CreatingCookieEventArgs.IsPersistent 속성

정의

현재 세션이 지난 후 인증 쿠키를 유지해야 하는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool IsPersistent { bool get(); };
public bool IsPersistent { get; }
member this.IsPersistent : bool
Public ReadOnly Property IsPersistent As Boolean

속성 값

현재 세션이 지난 후 쿠키를 유지해야 한다면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 이벤트 처리기는 CreatingCookie 이벤트입니다. 사용자 값을 검색 하는 처리기는 CreatingCookieEventArgs 인증 쿠키를 사용자 지정 하기 위해 개체입니다. IsPersistent 의 속성을 FormsAuthenticationTicket 개체가 값으로 설정 되는 IsPersistent 속성.

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

설명

만들 때를 FormsAuthenticationTicket 개체를 사용할 수는 IsPersistent 현재 세션이 지난 후 인증 쿠키를 유지 하는지 여부를 지정 하는 속성입니다.

적용 대상