首页 新闻 搜索 专区 学院

使用FormsAuthenticationTicket 似乎有一个BUG??

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-04-13 10:13

使用

Response.Redirect(FormsAuthentication.GetRedirectUrl(username, chkRememberMe.Checked));//可以读出UserData 但是记不住登录状态!即 chkRememberMe.Checked 记住登录无效

使用

FormsAuthentication.RedirectFromLoginPage(username, chkRememberMe.Checked); //可以记住登录状态,却读不出UserData

登录方法,及相关帖子如下:

http://social.microsoft.com/Forums/zh-CN/295/thread/08bcbce6-e59a-4362-ae5c-3e6bbd962e8e

 

    protected void BtnLogin_Click(object sender, EventArgs e)

    {

        string username = this.TxtUserName.Text;

        if (username.EndsWith("lkf", StringComparison.InvariantCultureIgnoreCase) && TxtUserPwd.Text.EndsWith("lkf", StringComparison.InvariantCultureIgnoreCase))

        {

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,

username,DateTime.Now,DateTime.Now.AddMinutes(30), true,  "admin|reader|editor",

FormsAuthentication.FormsCookiePath );

string encTicket = FormsAuthentication.Encrypt(ticket);

   Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

Response.Redirect(FormsAuthentication.GetRedirectUrl(username, chkRememberMe.Checked));//可以读出UserData 但是记不住登录状态!

 //FormsAuthentication.RedirectFromLoginPage(username, chkRememberMe.Checked); //可以记住登录状态,却读不出UserData

        }

        else

        {

            Response.Write("密码不正确");

        }

}

问题补充: 读取是在另一页面: protected void Page_Load(object sender, EventArgs e) { if (Page.User.Identity.IsAuthenticated) //是否登录成功 { FormsIdentity ident = User.Identity as FormsIdentity; Response.Write("Welcome back: " + Page.User.Identity.Name); Response.Write("
is admin? " + Page.User.IsInRole("admin")); Response.Write("
UserData: " + ident.Ticket.UserData); } }
钢的锅的主页 钢的锅 | 初学一级 | 园豆:14
提问于:2011-03-23 02:55
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册