-

- 加为好友
- 发送私信
- 在线聊天
|
| 发表于:2008-06-17 15:09:01 楼主 |
//webconfig: <authentication mode="Forms"> <forms name="FormLogin" loginUrl="~/LogIn.aspx" requireSSL="false" timeout="120" path="/"/> </authentication> <location path="~/Admins" > <system.web> <authorization> <allow roles="administrator,manager" /> <deny users="*" /> </authorization> </system.web> </location> //login.aspx.cs protected void Btn_LogIn_Click1(object sender, ImageClickEventArgs e) { sys_user LoginUser = new sys_user();//创建登陆用户 string user = tb_account.Text;//用户名 string password = tb_password.Text;//密码 int UserID = LoginUser.UserLoginCheck(user, password);//获取用户记录 if (UserID == 1) { string userData = LoginUser.GetUserRole(user);//获取用户角色 System.Web.Security.FormsAuthenticationTicket Ticket = new System.Web.Security.FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.AddMinutes(30), true, userData); //建立身份验证票对象 string HashTicket = FormsAuthentication.Encrypt(Ticket); HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket); Response.Cookies.Add(UserCookie); if (Context.Request["ReturnUrl"] != null) { Context.Response.Redirect("~/Admins/Default.aspx"); } else { Context.Response.Redirect("~/USers/Default.aspx"); } } else ...... } 运行结果是: 三个帐号登陆: 1 (user) 2(manager) 3(administrator) 第一次登陆都进到USers/Default.aspx 注销后出来再登陆就都进到Admins/Default.aspx了 估计我这个角色登陆验证是错误的,不知道错在哪,我是参考网上资料写的,却没有实现预期结果 郁闷呐! 希望熟手能出手相救. |
|
|
|
50
修改
删除
举报
引用
回复
| |