简体   繁体   English

ASP.NET您如何动态拒绝对角色的访问

[英]ASP.NET How do you dynamically deny access to Role

I recently starting trying to use the ASP.NET 4 Membership and Role providers in my web applications. 我最近开始尝试在Web应用程序中使用ASP.NET 4成员资格和角色提供程序。 But I'm having problems implementing a good security methodology. 但是我在实施良好的安全性方法时遇到了问题。

I understand that using web.config files we can grany or deny access to certain aspx files, but is there any good built in way to deny access to a specified Role on certain circumstances? 我了解使用web.config文件可以授予或拒绝访问某些aspx文件的权限,但是在某些情况下是否有任何好的内置方法可以拒绝对指定角色的访问?

For example; 例如;

We have a page called "EditUser.aspx". 我们有一个页面叫做“ EditUser.aspx”。

We have two user types; 我们有两种用户类型; administrators and a standard users. 管理员和标准用户。 This page is used to edit both types. 此页面用于编辑两种类型。 However, only administrators should be able to edit other administrators. 但是,只有管理员才可以编辑其他管理员。

What is the best approach to stop an authenticated user without the 'admin' role from being able to edit an administrator via EditUser.aspx? 阻止没有'admin'角色的经过身份验证的用户能够通过EditUser.aspx编辑管理员的最佳方法是什么?

I'm hoping for something a bit more elegant than the below: 我希望能得到比下面更好的东西:

if(editUser.IsInRole("admin") && !User.IsInRole("admin"))
{
    Respone.Redirect("SomeAccessDeniedPage.aspx");
}

Thanks, 谢谢,

Phil 菲尔

One thing to consider is to use the LoginView server control with the RoleGroups element. 要考虑的一件事是将LoginView服务器控件与RoleGroups元素一起使用。 Maybe bind the admin users in a separate gridview and wrap that in a LoginView set to only display to users in the admin role. 也许将管理员用户绑定到单独的gridview中,然后将其包装在LoginView中,以仅显示给具有admin角色的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM