开发者

ASP.NET How do you dynamically deny access to Role

开发者 https://www.devze.com 2023-03-25 16:26 出处:网络
I recently starting trying to use the ASP.NET 4 Membership and Role providers in my web applications. But I\'m having problems implementing a good security methodology.

I recently starting trying to use the ASP.NET 4 Membership and Role providers in my web applications. 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?

For example;

We have a page called "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 s开发者_运维问答top an authenticated user without the 'admin' role from being able to edit an administrator via 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消