授权整个安全组在ASP.Net MVC中执行操作

时间:2021-12-21 02:58:53

I'd like to authorize users to perform specific actions within my controllers. I've found the ASP.NET tutorial which explains how to allow individual users to perform specific actions but can this be extended to security groups? For example, would everyone belonging to the "domain\group" security group have access to the GetSecrets action if the code looked like this:

我想授权用户在我的控制器中执行特定操作。我找到了ASP.NET教程,该教程解释了如何允许单个用户执行特定操作,但是这可以扩展到安全组吗?例如,如果代码如下所示,属于“domain \ group”安全组的每个人都可以访问GetSecrets操作:

[Authorize(Users="domain\group")]
public ActionResult GetSecrets()
{ return View(); }

If not, how would I do this?

如果没有,我该怎么做?

1 个解决方案

#1


27  

You want to use the Roles property. Note that this can be a comma-separated list of roles.

您想要使用Roles属性。请注意,这可以是以逗号分隔的角色列表。

 [Authorize(Roles=@"domain\group")]

#1


27  

You want to use the Roles property. Note that this can be a comma-separated list of roles.

您想要使用Roles属性。请注意,这可以是以逗号分隔的角色列表。

 [Authorize(Roles=@"domain\group")]