如何在asp.net mvc3中设置角色 [英] How to set roles in asp.net mvc3

查看:104
本文介绍了如何在asp.net mvc3中设置角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我一直在寻找设置自定义身份验证我发现我们必须为用户设置角色

喜欢这个

Hi,
I was looking for set custom authentication I found we must set role to user
like this

Roles.AddRoleToUser(userName, RoleName)



发现我必须在我的webconfig中配置


and found that I must put configuration in my webconfig

<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>





但是在webconfig中添加这些行时运行应用程序时出现配置错误!



并从webconfig中删除roleManager

并尝试向用户添加角色

我得到了



but I have Configuration Error when run application when add those lines in webconfig!

and when remove roleManager from webconfig
and try to add role to user
I got

Unable to connect to SQL Server database





任何帮助?



any help?

推荐答案

你好,



请点击以下链接:

使用身份验证和授权保护应用程序ASP.NET站点 [ ^ ]

在这里你可以找到以适当的方式实现的指南,MVC3中的Rles。



谢谢
Hello,

Please follow the below link:
Secure Applications Using Authentication and Authorization | The ASP.NET Site[^]
Here you can find the guide to implement in a proper way, Rles in MVC3.

Thanks


这篇关于如何在asp.net mvc3中设置角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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