【问题标题】:ASP.Net MVC Security AuthorizeAttributeASP.Net MVC 安全 AuthorizeAttribute
【发布时间】:2016-03-21 22:51:24
【问题描述】:

我正在使用 EF6 Web 应用程序制作 MVC4,其中允许管理员访问某些页面。在这种情况下,管理员可以访问“部门”页面。

我通过在我的 User.cs 类中使用 public bool IsAdministrator { get; set; } 来区分我的管理员和普通用户。

每当我登录 isAdministrator = true 的用户帐户并尝试单击部门的 index.cshtml 时,它都会将我重定向到登录页面而不是部门页面。我正确使用 AuthorizeAttribute 了吗?

DepartmentController.cs

   [Authorize(Roles = "isAdministrator")]
    public class DepartmentController : Controller
    {
          ...
    }

Users.cs

public class User
{
    public int UserID { get; set; }

    public bool IsAdministrator { get; set; }
}

【问题讨论】:

    标签: c# asp.net-mvc entity-framework security


    【解决方案1】:

    您是否设置了角色 isAdministrator

    类中的简单布尔属性不会为您执行此操作。

    有关如何使用/创建角色的更多信息,请参阅以下文章。

    creating-roles-in-asp-net-identity-mvc-5

    Extending-and-Modifying-Roles

    【讨论】:

    • 是的,我没有!我会查看您建议的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多