如何从身份验证票证中获取userdata字符串?

时间:2013-11-21 12:31:32

标签: c# asp.net cookies webforms

我添加了一个字符串作为用户身份,但无法找到如何从类中检索它。

FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;

tkt = new FormsAuthenticationTicket(1, txtUser.Text, DateTime.Now,              
//Amount of minutes for standard session
DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, UserCompany);
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);

1 个答案:

答案 0 :(得分:0)

到最后......

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


        CompanyID = ticket.UserData;