【问题标题】:RESTRICT ACCESS TO Controller ACTIONS For a list of users in MVC4限制对控制器操作的访问对于 MVC4 中的用户列表
【发布时间】:2014-06-06 09:35:36
【问题描述】:

我有一个使用自定义授权属性的 MVC4 应用程序,允许某些角色的用户访问该应用程序。此授权属性位于控制器上,这意味着授权用户将有权访问该控制器内的所有操作。

但是,一些授权用户只需要访问该控制器内的一项操作。

我真正想要的是一个操作过滤器,它可以列出不应访问某些操作的用户。

就最佳实践而言,解决此问题的适当方法是什么?

【问题讨论】:

    标签: asp.net-mvc-3 asp.net-mvc-4


    【解决方案1】:

    我想你想要这样

    [Authorize(Roles = "HrAdmin, CanEnterPayroll")]
    [HttpPost]
    public ActionResult EnterPayroll(string id)
    {
        //  . . . Enter some payroll . . . 
    }
    
    
    [Authorize(Roles = "HrAdmin, CanEditPayroll, CanProcessPayroll")]
    [HttpPost]
    public ActionResult EditPayroll(string id)
    {
        //  . . . Edit existing payroll entries . . . 
    }
    
    [Authorize(Roles = "HrAdmin, CanProcessPayroll")]
    [HttpPost]
    public ActionResult ProcessPayroll(string id)
    {
        //  . . . Process payroll and cut checks . . . 
    }
    

    有关角色和权限,您可以参考此链接。 Implementing Group-Based Permissions Management

    【讨论】:

      猜你喜欢
      • 2016-05-27
      • 2015-10-12
      • 2013-12-08
      • 2023-04-07
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多