Servicestack:按角色限制 MVC 操作

Servicestack: restrict MVC action by role

我想限制角色的 ASP.NET MVC 操作。我认为应该是这样的:

[Restrict(RestrictPermission = new []{Permissions.Admin, Permissions.Admin_Export  })]
public class LocalAdmin { }

如何删除某些角色的操作权限?

ServiceStack 的 [Restrict] Attribute 仅用于根据调用服务的请求属性限制对服务的访问。

有关根据用户是否具有访问服务所需的角色来限制服务访问的示例,请参见Required Role and Permission attributes

您可以在继承 ServiceStackController 的 MVC 控制器上应用的 mvc.servicestack.net Live Demo shows an Example of Restricting Access by Role,例如:

[RequiredRole("TheRole")]
public class RequiresRoleController : ServiceStackController 
{
    public ActionResult Index()
    {
        var session = SessionAs<CustomUserSession>();
        return View(session);
    }
}