【问题标题】:FluentSecurity with MVCSiteMapProvider使用 MVSiteMapProvider 的 FluentSecurity
【发布时间】:2012-05-04 01:41:34
【问题描述】:

我希望将它与 MvcSiteMapProvider 一起使用来隐藏/显示菜单项,而不是在我的 mvc.sitemap 文件中加倍和定义角色。

我已经浏览了 2.0alpha1 的源代码,但似乎无法弄清楚如何执行以下操作:

bool hasAccess = SecurityConfiguration.Current.HasAccess(controller, action, area)

谁能指出我正确的方向?

谢谢

【问题讨论】:

    标签: asp.net-mvc-3 mvcsitemapprovider fluent-security


    【解决方案1】:

    我能够在实际 github 项目页面上的 kristoffer-ahl 的帮助下解决这个问题

    解决办法

    public static bool ActionIsAllowedForUser(string area, string controllerName, string actionName)
    {
        var configuration = SecurityConfiguration.Current;
    
        string fullControllerName = string.Format("Web.Controllers.{0}Controller", controllerName);
        if (!string.IsNullOrEmpty(area))
        {
            fullControllerName = string.Format("Web.Areas.{0}.Controllers.{1}Controller", area, controllerName);
        }
    
        var policyContainer = configuration.PolicyContainers.GetContainerFor(fullControllerName, actionName);
        if (policyContainer != null)
        {
            var context = SecurityContext.Current;
            var results = policyContainer.EnforcePolicies(context);
            return results.All(x => x.ViolationOccured == false);
        }
        return true;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多