asp.net成员资格 - 如何以编程方式确定用户是否在角色中
-
06-07-2019 - |
题
确定用户是否在角色中的代码是什么?
我已经通过ASP.NET配置安全性选项卡设置了所有用户,但现在想要在某些关键区域放置逻辑,这样只有某些角色的人才能看到和访问这些区域。
解决方案
if (User.IsInRole("rolename")) {
// my action
}
其他提示
易于〜
HttpContext.Current.User.IsInRole("roleName")
查看角色课程,特别是IsUserInRole,GetUsersInRole,AddUserToRole等。
我一直都在使用这些。
感谢“Chris Van Opstal”。我这样解决了我的问题,
public ActionResult Index()
{
if (User.IsInRole("Supervisor"))
{
return RedirectToAction("Index", "InvitationS");
}
return View();
}
不隶属于 StackOverflow