基于角色的表单身份验证在ASP.Net中不起作用 [英] Role based Form Authentication not working in ASP.Net

查看:84
本文介绍了基于角色的表单身份验证在ASP.Net中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试在我的网站中实现基于角色的表单身份验证,并且一直坚持使用它。问题是它不会根据用户角色重定向用户。



以下是验证用户身份的代码。我想只允许具有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.

推荐答案

http://www.asp.net/web-forms/tutorials / security / roles / role-based-authorization-cs [ ^ ]



基于角色的安全性与表单身份验证 [ ^ ]



表单身份验证和基于角色的授权:更快,更简单,更正确的方法 [ ^ ] < br $>




检查以上链接..希望你能解决它..
http://www.asp.net/web-forms/tutorials/security/roles/role-based-authorization-cs[^]

Role-based Security with Forms Authentication[^]

Forms Authentication and Role based Authorization: A Quicker, Simpler, and Correct Approach[^]


Check the above links..hope u will be able to sort it out..


这篇关于基于角色的表单身份验证在ASP.Net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆