web.config设置了 但是用户不能登陆
UserInfo.SetCookie(1, username, "admin");程序代码:
/// <summary> /// 赋值Cookie /// </summary> /// <param name="day">过期时间</param> /// <param name="username">用户名</param> /// <param name="roles">权限</param> public static void SetCookie(int day, string username, string roles) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket ( 1, // 票据版本号 username.ToString().Trim(), // 票据持有者 DateTime.Now, // 分配票据的时间 DateTime.Now.AddDays(day), // 票据失效时间 false, // 是否持久性的 cookie roles.ToString().Trim() // 用户数据,这里其实就是用户的角色 ); string hashTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket); cookie.Path = FormsAuthentication.FormsCookiePath; cookie.Domain = FormsAuthentication.CookieDomain; cookie.Expires = ticket.Expiration; //将cookie的失效时间设置为和票据tikets的失效时间一致 HttpContext.Current.Response.Cookies.Add(cookie); }
程序代码:
<location path="Manager"> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web> </location> <connectionStrings/> <system.web>
但是输入正确的用户名和密码后,无法进去