FormsAuthenticationTicket tk = new FormsAuthenticationTicket(
1, //指定版本号:可随意指定
memberid.ToString(), //登录用户名:对应 Web.config 中 <allow users="Admin" … /> 的 users 属性
System.DateTime.Now, //发布时间
System.DateTime.Now.AddYears(100), //失效时间:100 年以后,够永够久了吧
true,
“我的信息” //用户数据:可用 ((System.Web.Security.FormsIdentity)User.Identity).Ticket.UserData 获取
);
//HttpContext.Current.Items["UseInfo"] = null;//reset the infor string str = FormsAuthentication.Encrypt(tk);//加密身份验票
System.Web.HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, str);
我在login页面里面在userData里面放入我的信息,
在
void application_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
if (context.Request.IsAuthenticated)
{
HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);//解密
string UseInfo = authTicket.UserData;
里面把userData取出来,为什么就是空了呢?还有,我在login里面把cook设定到100年后过期,我取得时候,怎么又是立刻过期呢?
1, //指定版本号:可随意指定
memberid.ToString(), //登录用户名:对应 Web.config 中 <allow users="Admin" … /> 的 users 属性
System.DateTime.Now, //发布时间
System.DateTime.Now.AddYears(100), //失效时间:100 年以后,够永够久了吧
true,
“我的信息” //用户数据:可用 ((System.Web.Security.FormsIdentity)User.Identity).Ticket.UserData 获取
);
//HttpContext.Current.Items["UseInfo"] = null;//reset the infor string str = FormsAuthentication.Encrypt(tk);//加密身份验票
System.Web.HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, str);
我在login页面里面在userData里面放入我的信息,
在
void application_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
if (context.Request.IsAuthenticated)
{
HttpCookie authCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);//解密
string UseInfo = authTicket.UserData;
里面把userData取出来,为什么就是空了呢?还有,我在login里面把cook设定到100年后过期,我取得时候,怎么又是立刻过期呢?
----------------
从来msdn都是这样
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
return 0;
FormsIdentity useridentity = (FormsIdentity)(HttpContext.Current.User.Identity);
string userdatastr = useridentity.Ticket.UserData;
return userdatastr;
}