@if(User.IsInRole("系统管理员","管理员"))

时间:2017-05-11 12:35:51

标签: asp.net-mvc

我想授予系统管理员和管理员权限,但在我写作时  @if(User.IsInRole("系统管理员","管理员"))得到错误(方法没有重载' IsINRole'带2个参数)尽管在控制器上它是工作

[CustomAuthorize(Roles ="系统管理员,管理员")]     public class CategoriesController:Controller

我还有其他方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您无法将多个角色传递给IsInRole功能。但您可以使用c#中的||功能,如下所示。

@if (User.IsInRole("System Administrator") || User.IsInRole("Administrator"))
{
    //your code here
}
相关问题