首页 新闻 会员 周边

Form验证

0
[已关闭问题] 关闭于 2012-08-31 19:48

现在有一个方法btnLogin_Click,我在其中存了票证,存过后在这个方法中去取User.Identity.Name==“”,
但是在另外其他方法中User.Identity.Name确有值,这是为什么啊?
第一次走那个setTickets然后票证理是有值的,但是一担走LbOutLogin_Click他过后,在往票证理去写东西都写不进去,存后即可取值是“”。在其他方法调用不是null。

问题补充:
/// <summary>
        /// 设置票据
        /// </summary>
        /// <param name="userName">登录名</param>
        /// <param name="rules"></param>
        /// <param name="expires">是否持续</param>
        public static void SetTicket(UserEntity user, string rules, bool expires)
        {
            string ticketName = user.ToArray();
            SetTickets(ticketName, rules, expires);
        }
        public static void SetTickets(string ticketName, string rules, bool expires)
        {
            //暂时为永不过期
            //expires = false;
            HttpContext context = HttpContext.Current;
            string userDate = rules;
            DateTime expiration = DateTime.Now.AddMinutes(20);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
            1,  // 版本号
            ticketName,  // 票据名
            DateTime.Now,  // 票据发出时间
            DateTime.Now.AddYears(100),  // 过期时间
            true,  // 是否持久
             userDate// 存储在 Cookie 中的用户定义数据,这里用来存取用户组
            );
            // Encrypt the ticket
            string cookieStr = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieStr);

            if (!string.IsNullOrEmpty(FormsAuthentication.CookieDomain))
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
                cookie.Path = "/";
            }
            else
            {
                //如果过期
                if (expires)
                {
                    cookie.Expires = expiration;
                }
            }
            context.Response.Cookies.Add(cookie);
        }

 //退出
        protected void LbOutLogin_Click(object sender, EventArgs e)
        {
            tblLoginAfter.Visible = false;
            tblLoginBefure.Visible = true;
            HttpContext context = HttpContext.Current;
            FormsAuthentication.SignOut();
            HttpCookie c = context.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (c == null)
            {
                return;
            }
            c.Expires = DateTime.Now.AddMinutes(-20);
            context.Response.SetCookie(c);


        }

 

 
rains的主页 rains | 小虾三级 | 园豆:860
提问于:2012-08-28 08:59
< >
分享
所有回答(1)
0

方法btnLogin_Click在哪啊大哥。。。能顺便把你的page_load处的代码贴一下吗

羽商宫 | 园豆:2490 (老鸟四级) | 2012-08-28 11:26

page_load没有任何代码

支持(0) 反对(0) rains | 园豆:860 (小虾三级) | 2012-08-28 13:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册