确定用户是否在某个角色中的代码是什么?
我已经通过 ASP.NET 配置安全选项卡设置了所有用户,但现在想在一些关键区域周围放置逻辑,以便只有特定角色的人才能看到和访问这些区域。
确定用户是否在某个角色中的代码是什么?
我已经通过 ASP.NET 配置安全选项卡设置了所有用户,但现在想在一些关键区域周围放置逻辑,以便只有特定角色的人才能看到和访问这些区域。
if (User.IsInRole("rolename")) {
// my action
}
轻松~
HttpContext.Current.User.IsInRole("roleName")
查看Roles类,特别是 IsUserInRole、GetUsersInRole、AddUserToRole 等。
我一直在使用这些。
感谢“Chris Van Opstal”。我这样解决了我的问题,
public ActionResult Index()
{
if (User.IsInRole("Supervisor"))
{
return RedirectToAction("Index", "InvitationS");
}
return View();
}