首页 新闻 搜索 专区 学院

ASP.NET MVC环境下利用Froms窗体认证失败的问题!!

0
悬赏园豆:50 [待解决问题]

想请教下你是怎么解决这个问题,我是mvc3+表单认证 但有些客户会出现登录密码和帐号都对,但是系统无法获取cookie,IsAuthenticated 一直为False 。一直解决不了这个问题,还请多多指教,附上登录验证代码。

HttpCookie authCookie = FormsAuthentication.GetAuthCookie(username, true);
            FormsAuthenticationTicket orgticket = FormsAuthentication.Decrypt(authCookie.Value);
            DateTime outtime = autologin ? DateTime.Now.AddDays(7) : DateTime.Now.AddHours(8);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(orgticket.Version, orgticket.Name, DateTime.Now, outtime, true, companyId.ToString() + "|" + companyname + "|1|" + item.lastlogintime + "|" + userType);
            string encTicket = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
            {
                HttpOnly = true,
                Path = ticket.CookiePath,
                Expires = ticket.IsPersistent ? ticket.Expiration : DateTime.MinValue,
                Domain = FormsAuthentication.CookieDomain,
            };
            HttpContext.Response.Cookies.Add(cookie);
中国医学人才网的主页 中国医学人才网 | 初学一级 | 园豆:152
提问于:2012-10-16 09:17
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册