【问题标题】:Allowing access to multiple Roles Using User.IsInRole使用 User.IsInRole 允许访问多个角色
【发布时间】:2016-11-01 16:14:18
【问题描述】:
@if (User.IsInRole("Admin")) {
//Link goes here.
}

这一切都很好,但当我想允许多重角色时我该怎么办,例如:

@if (User.IsInRole("Admin, SuperUser")) {
//Link goes here.
}

【问题讨论】:

  • if (User.IsInRole("Admin") || User.IsInRole("SuperUser"))
  • @BradleyUffner 你是对的 :)

标签: c# asp.net-core-mvc asp.net-identity-3


【解决方案1】:

您应该使用条件或运算符 (||)。 请参阅此处的 Microsoft 文档:https://msdn.microsoft.com/en-us/library/6373h346.aspx

@if (User.IsInRole("Admin") || User.IsInRole("SuperUser") {
//Link goes here.
}

【讨论】:

  • @Chantry 如果这是解决方案,请标记为答案。
猜你喜欢
  • 2010-10-16
  • 2013-02-05
  • 2021-04-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-30
  • 1970-01-01
  • 2020-09-07
  • 2019-11-12
相关资源
最近更新 更多