C# 如何使用Asp.NETMVC通过配置文件创建安全策略?
我正在使用Asp.NETMVC创建一个系统,但在开始开发之前,我需要定义安全策略。我想通过profile创建它,其中每个profile都有访问权限,例如:profile Administrative all permissions、profile Common restrict access、profile Manager和profile Administrative的一些权限 我想通过方法的名称或控制器创建一个具有权限的概要文件,并将权限设置为布尔值true/false,例如:方法addNewProduct,无论此方法是否仅适用于概要文件管理/管理器,我将仅为它们授予权限,我不知道如何获得控制器或方法的名称来授予这些权限 例如: 轮廓C# 如何使用Asp.NETMVC通过配置文件创建安全策略?,c#,asp.net-mvc,asp.net-mvc-4,C#,Asp.net Mvc,Asp.net Mvc 4,我正在使用Asp.NETMVC创建一个系统,但在开始开发之前,我需要定义安全策略。我想通过profile创建它,其中每个profile都有访问权限,例如:profile Administrative all permissions、profile Common restrict access、profile Manager和profile Administrative的一些权限 我想通过方法的名称或控制器创建一个具有权限的概要文件,并将权限设置为布尔值true/false,例如:方法addNew
我怎么能这样做?有什么建议吗?您需要的不是配置文件而是角色,这种技术称为基于角色的授权 在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身份验证,则Authorize属性将在Active Directory中查找用户的组,以确认用户是否属于这些组中的一个
[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();
}
}