开发者

Read form authentication cookie from asp.net code behind

开发者 https://www.devze.com 2023-03-31 20:03 出处:网络
We know that form authentication cookie is encrypted. so how to read the form authentication cookie conten开发者_StackOverflow中文版t from my code behind.

We know that form authentication cookie is encrypted. so how to read the form authentication cookie conten开发者_StackOverflow中文版t from my code behind.

if (Request.Cookies[".ASPXAUTH"] != null)
{
    HttpCookie myCookie = new HttpCookie(".ASPXAUTH");
}


You can access the ticket with the Decrypt method provided by FormsAuthentication

HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);

string cookiePath = ticket.CookiePath;
DateTime expiration = ticket.Expiration;
bool expired = ticket.Expired;
bool isPersistent = ticket.IsPersistent;
DateTime issueDate = ticket.IssueDate;
string name = ticket.Name;
string userData = ticket.UserData;
int version = ticket.Version;
0

精彩评论

暂无评论...
验证码 换一张
取 消