Asp.net 需要Web.config授权中的多个角色

Asp.net 需要Web.config授权中的多个角色,asp.net,authorization,roles,web-config,Asp.net,Authorization,Roles,Web Config,是否可以指定web.config文件的authorization元素中需要多个角色?我当前在我的网站的一个web.config中为特定目录设置了此块: <authorization> <allow roles="Global, Region" /> <deny users="*" /> </authorization> 我刚刚确定了一个特殊情况,即具有比全局和区域更低级别权限的人也应该访问此目录。大致上,我想要这样的东西:

是否可以指定web.config文件的authorization元素中需要多个角色?我当前在我的网站的一个web.config中为特定目录设置了此块:

<authorization>  
    <allow roles="Global, Region" />
    <deny users="*" />
</authorization>

我刚刚确定了一个特殊情况,即具有比全局和区域更低级别权限的人也应该访问此目录。大致上,我想要这样的东西:

<authorization>  
    <allow roles="GlobalManager, RegionManager, SiteManager && FooSite" />
    <deny users="*" />
</authorization>


有什么想法吗?我意识到我可能应该在这个场景中扮演一个新角色,但我想避免这样。谢谢

我认为您无法通过web.config中允许的当前配置来实现这一点。但是你可以做的是如下所示。。。作为有关页面的
页面加载
事件的第一行,请使用以下代码(VB):

当然,这一行假设您正在使用FormsAuthentication。如果没有,则需要根据您的身份验证方法,使用适当的代码替换
FormsAuthentication.RedirectToLoginPage()

我不清楚您的具体情况,但根据您的代码,您似乎可以更进一步,添加一个带有用户到站点映射的表,并执行以下操作:

在公共模块中,添加以下代码:

<System.Runtime.CompilerServices.Extension()> _
Public Function ManagesSite(target As System.Security.Principal.IPrincipal, siteName As String) As Boolean
    Return [ code here to look up whether this user can access the site specified ]
End Function 

我通常使用的解决方法是在设置用户角色时,创建虚拟角色。因此,如果您希望仅允许学生管理员访问页面,而用户同时具有学生和管理员角色,则可以添加新的学生管理员角色。

不幸的是,我认为这是不可能的。我正试着用一台计算机做同样的事情-(
<System.Runtime.CompilerServices.Extension()> _
Public Function ManagesSite(target As System.Security.Principal.IPrincipal, siteName As String) As Boolean
    Return [ code here to look up whether this user can access the site specified ]
End Function 
If Not (User.IsInRole("SiteManager") AndAlso User.ManagesSite(Request.Url.Host)) Then _
    FormsAuthentication.RedirectToLoginPage()