本文介绍了基于角色的表单身份验证在ASP.Net中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试在我的网站中实现基于角色的表单身份验证,并且一直坚持使用它。问题是它不会根据用户角色重定向用户。 以下是验证用户身份的代码。我想只允许具有Admin角色的用户访问Admin文件夹中的页面。即使提供了正确的ID和密码,管理员也无法重定向到Login.aspx。Hi,I am trying to implement Role based Form Authentication in my Website and been stuck with it. Problem is its not redirecting the user depending on the user role.Below is the code to authenticate the user. I want to allow only user with Admin role to access pages inside Admin folder. Even after providing correct id and password the Admin is not able redirected to Login.aspx.if (isValidUser) { string role = "Admin"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes(1), false, role, FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(ticket); Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); Response.Redirect("~/Admin/admin_index.aspx"); } else Response.Redirect("Login.aspx"); 从我的Web.Config中提取Extracts from my Web.Config<authentication mode="Forms"> <forms loginUrl="Login.aspx" timeout="1" cookieless="UseDeviceProfile"/></authentication><authorization> <deny users="?"/></authorization><location path="Admin"> <system.web> <authorization> <allow roles="Admin"/> <deny users="*"/> </authorization> </system.web></location> 非常感谢任何帮助。Any help really appreciated.推荐答案 这篇关于基于角色的表单身份验证在ASP.Net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 08:23
查看更多