【问题标题】:How to make some actions (pages) in the controller accessed only by certain members ? (asp.net-MVC)如何使控制器中的某些操作(页面)仅由某些成员访问? (asp.net-MVC)
【发布时间】:2013-11-24 02:10:36
【问题描述】:

好的,所以我创建了一个登录页面并用 [Authorize] 修饰了我的所有操作,因此只有登录的人才能访问它,现在我希望一些用户(管理员)可以访问某些操作(页面)。

我的用户表如下

userID , Username , password, name(idk why) , class ( 1 for normal users, 2 for admins )

那我该怎么做呢?

编辑:如果这样更容易,它只有一个管理员。

【问题讨论】:

    标签: asp.net-mvc authentication


    【解决方案1】:

    您仍然可以使用 Authorize 属性,例如 [Authorize(Roles = "Admin")][Authorize(Users = "John")]。请参阅下面的示例:

    [Authorize(Users = "John")]
    public ActionResult Secret()
    {
        return View();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2022-11-26
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多