开发者

Read form authentication cookie from asp.net 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜