Asp.net mvc Identity Server 4如何将角色列表映射到MVC应用程序

Asp.net mvc Identity Server 4如何将角色列表映射到MVC应用程序,asp.net-mvc,asp.net-core,identityserver4,Asp.net Mvc,Asp.net Core,Identityserver4,在Identity Server 4中,我为用户创建角色声明“Admin”: userMgr.AddClaimsAsync(user, new Claim[]{ new Claim("role", "Admin") }) 在客户端应用程序中,我映射了这个角色,它只适用于一个角色: options.Scope.Add(RSIdentityServerConstants.Roles); options.ClaimActions.MapJsonKey("role", "role", "role")

在Identity Server 4中,我为用户创建角色声明“Admin”:

userMgr.AddClaimsAsync(user, 
new Claim[]{ new Claim("role", "Admin") })
在客户端应用程序中,我映射了这个角色,它只适用于一个角色:

options.Scope.Add(RSIdentityServerConstants.Roles);
options.ClaimActions.MapJsonKey("role", "role", "role");
options.TokenValidationParameters.NameClaimType = "name";
options.TokenValidationParameters.RoleClaimType = "role";

[Authorize(Roles = "Admin")]  => Works fine
public IActionResult Index()
{
  return View();
}

但是我需要映射角色列表,但我不知道如何创建声明并映射到asp net核心mvc应用程序

[Authorize(Roles = "Admin, SuperAdmin, Others")]  => How to do ??
public IActionResult Index()
{
  return View();
}

userMgr.AddClaimsAsync(user, 
new Claim[]{ new Claim("role", "Admin, SuperAdmin, Others") })  => this doesn't work

只需以数组方式添加
声明

new Claim[]{ new Claim("role", "Admin"), new Claim("role", "SuperAdmin"), ...  }) 

只需以数组方式添加
声明

new Claim[]{ new Claim("role", "Admin"), new Claim("role", "SuperAdmin"), ...  })