apt.net成员资格提供者不使用固定配置

时间:2011-06-23 14:28:57

标签: c# asp.net asp.net-membership membership-provider roleprovider

在成员资格提供程序中,有一些机制可以使用web.config文件在页面级别提供身份验证和授权,并使用装饰器保护方法。

我很擅长使用这个asp.net http://msdn.microsoft.com/en-us/library/yh26yfzy(v=VS.90).aspx

我的问题是,有没有一种方法可以将它们存储在.config文件和代码中,但是要将它们存放在sql数据库中,以便可以管理管理以允许多种“角色”和动态的安全性?

我的意思是:

web.config文件:

<?xml version="1.0"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
    <appSettings/>
    <connectionStrings/>
     <system.web>
      <authorization>
        <allow roles="Administrators" />
        <deny users="*"/>
      </authorization>
    </system.web>
</configuration>

装饰方法的示例剪辑:

[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
[PrincipalPermission(SecurityAction.Demand, Role = "Supervisors")]
protected void UserGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

特别是,我会对数据库Party数据模型模式/实践可以用于促进授权以及特定用户的身份验证而不具有在配置或代码中定义的角色的示例感兴趣。我错过了一些我应该知道/意识到的东西吗?

2 个答案:

答案 0 :(得分:0)

一种方法是创建一个中间表Group,其中Users分配给GroupsGroups分配给Roles

因此,您的multiple roles要求将转换为multiple groups

[PrincipalPermission(SecurityAction.Demand, Role = "SingleRole")]
protected void UserGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

您必须编写自定义RoleProvider才能实现此目的。

答案 1 :(得分:0)

您发布的示例包含授权数据。两者都定义了对某些角色的asp.net资源的访问级别。所以您真正要问的是,有没有办法以基于SQL的方式在ASP.NET中配置授权,这样您就可以更改角色从SQL访问内容的权限,而无需直接修改源代码或配置。

我不知道直接这样做的任何方式,但我可以建议在SQL中将自己的角色/组结构插入到内置角色结构中,以便ASP.NET角色定义资源和级别访问,并且可以在描述和跟踪您的Party数据模型时动态更改SQL组/角色。

相关问题