我正在保护 ASP.NET MVC 2 应用程序,并且我有一个角色为“Foo”的用户。
这是真的:
User.IsInRole("Foo")
但是,当我尝试锁定如下所示的 Controller 操作时,用户被拒绝:
[Authorize(Roles = "Foo")]
public ActionResult PrivatePage()
{
return View();
}
如果 IsInRole 报告为 true,为什么 Authorize 属性不允许用户进入?
最佳答案
如果您为表单例份验证 cookie 存储持久性 cookie,则可能会导致这种情况。在这种情况下,IsInRole 可能会检查 cookie,而无需验证最新的登录信息。
关于asp.net - 为什么 User.IsInRole 会返回 true,而 AuthorizeAttribute 不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4798256/