仅将UmbracoAuthorizedController限制为Umbraco管理员用户

问题描述 投票:0回答:1

我创建了一个新的控制器,它继承自Umbraco.Web.Mvc.UmbracoAuthorizedController,并试图将其限制为仅登录Umbraco管理员

我当前的解决方案仅显示已登录的umbraco用户的视图,但我不能仅过滤管理员。

代码:

我有一个作曲家,并且设置了路由配置:

public class ApplicationEventComposer : IComposer
{
    public void Compose(Composition composition)
    {
        RouteTable.Routes.MapRoute(
            name: "ITTest",
            url: "umbraco/backoffice/ITTest/{action}/{id}",
            defaults: new { controller = "ITTest", action = "Index", id = UrlParameter.Optional }
        );
        composition.Register<ITTestController>(Lifetime.Request);
    }
}

我有一个控制器:

public class ITTestController : Umbraco.Web.Mvc.UmbracoAuthorizedController
{
   public ActionResult Index()
   {
       return View("/Views/ITTest/Index.cshtml");
   }
}

我尝试添加其他属性以仅针对管理员进行过滤:

[UmbracoAuthorize(Roles = "admin")]
[UmbracoApplicationAuthorize(Roles = "admin")]
[AdminUsersAuthorize]

并尝试过不同的角色,例如“管理员”,“管理员”,“管理员”,“管理员”等,但似乎无济于事。

(注意:目前,我正在考虑一种解决方法,并覆盖OnAuthorization事件,但这比真正的解决方案更像是骇客。)

问题:

  • 如何使用Umbraco角色过滤用户?
  • 确切的角色名称是什么?他们是用户组名称还是其他名称?
c# authorization umbraco umbraco8
1个回答
0
投票

Umbraco文档:

https://our.umbraco.com/documentation/Implementation/Controllers/

建议您应该使用Umbraco.Web.Mvc.UmbracoAuthorizeAttribute属性,我认为您已经尝试过,因此我将把Roles更新为Roles = "Administrators",所以您会有类似的内容:

[UmbracoAuthorize(Roles = "Administrators")]
public ActionResult Index()
{
   return View("/Views/ITTest/Index.cshtml");
}
© www.soinside.com 2019 - 2024. All rights reserved.