我有以下代码:
var httpCookie = context.HttpContext.Request.Cookies[".ASPXAUTH"];
这适用于Firefox。列出并找到[“.ASPXAUTH”]。但是在Chrome和IE9中它丢失了,因此httpCookie为null。
为什么会这样,我该如何解决这个问题?
非常感谢提前。
答案 0 :(得分:3)
要获取应用程序身份验证的cookie,您可以尝试以下方法:
HttpCookie appCookie = context.HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
解密它,你可以使用:
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(appCookie.Value);
// you can access all properties using the 'ticket' object.
string cookikePath = 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;
string version = ticket.Version;