【发布时间】:2021-05-03 22:17:42
【问题描述】:
有人可以帮助我了解它在 Asp.net 中的工作原理吗?如何在 Razor 视图中检查用户(未登录)的角色?
假设这样的情况: 在控制器中,我得到了所有用户的列表:
var Users = await _context.ApplicationUser.ToListAsync()
return View(Users);
在视图中:
@foreach ( var user in Users){
if (user.IsInRole("Admin")) <---- check here if the user is in role
{
do something
}
}
如何检查是否为每个用户分配了特定角色?
【问题讨论】:
标签: asp.net asp.net-core authentication roles