如何使用 Asp.Net MVC 按配置文件创建安全策略?

How do I to create a security policy by profile using Asp.Net MVC?

我正在使用 Asp.Net MVC 创建一个系统,但在开始开发之前我需要定义安全策略。我想通过配置文件创建它,其中每个配置文件都有权访问,例如:配置文件管理(所有权限)、配置文件通用(限制访问)、配置文件管理器(具有配置文件管理的某些权限)。

我想通过 方法的名称或控制器 创建一个具有权限的配置文件,并将权限作为布尔值 true/false,例如:方法 addNewProduct(),是否此方法仅适用于配置文件Administrative/Manager我只会为他们授予权限,但是,我不知道如何才能获得控制器或方法的名称来授予这些权限。

示例:

个人资料

Administrative      |   Common             |   Manager
[x]addNewProduct    |   []addNewProduct    |   [x]addNewProduct

我该怎么做?有什么建议吗?

您要查找的不是 profiles,而是 roles,该技术称为 Role-Based Authorization .

在ASP.NET MVC中,你可以这样使用它:

[Authorize] //ensure a user is signed-in
public class MyController : Controller
{
    [Authorize(Roles = "Administrative,Manager")] // ensure the user is signed in and belongs in one of the roles
    public ActionResult DoSomething()
    {
        return View();
    }
}

此处,例如,如果启用了Windows Authentication,则Authorize属性将在Active Directory中查找用户的Groups,以确认用户是否属于这些组之一或不。