【问题标题】:@if (User.IsInRole("System Administrator","Administrator")) [duplicate]@if(User.IsInRole(“系统管理员”,“管理员”))[重复]
【发布时间】:2017-10-10 11:12:02
【问题描述】:

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

[CustomAuthorize(Roles = "系统管理员,管理员")] 公共类 CategoriesController : 控制器

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

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    您不能将多个角色传递给IsInRole 函数。但是您可以在 c# 中使用|| 功能,如下所示。

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

    【讨论】:

    • 效果很好,非常感谢!!
    猜你喜欢
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多