阅读从asp.net code后面的形式验证cookie [英] Read form authentication cookie from asp.net code behind

查看:102
本文介绍了阅读从asp.net code后面的形式验证cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,形式验证cookie进行加密。因此如何读取我的code背后的形式验证cookie的内容。

 如果(Request.Cookies时[。ASPXAUTH]!= NULL)
{
    的HttpCookie myCookie时=新的HttpCookie(ASPXAUTH。);
}


解决方案

您可以与FormsAuthentication提供的解密方法访问票

 的HttpCookie authCookie = Request.Cookies时[FormsAuthentication.FormsCookieName]
的FormsAuthenticationTicket票= FormsAuthentication.Decrypt(authCookie.Value);字符串cookiePath = ticket.CookiePath;
日期时间过期= ticket.Expiration;
布尔过期= ticket.Expired;
布尔isPersistent = ticket.IsPersistent;
日期时间issueDate = ticket.IssueDate;
字符串名称= ticket.Name;
字符串用户数据= ticket.UserData;
INT版本= ticket.Version;

We know that form authentication cookie is encrypted. so how to read the form authentication cookie content 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;

这篇关于阅读从asp.net code后面的形式验证cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆