2012-05-04 77 views
2

我希望能用這與MvcSiteMapProvider隱藏/顯示菜單項,而不是在我的mvc.sitemap文件中加倍和定義角色。FluentSecurity與MVCSiteMapProvider

我已經通過源走了2.0alpha1,但似乎無法弄清楚如何做這樣的事情:

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

任何人都可以點我在正確的方向?

感謝

回答

3

我能夠與kristoffer-ahl實際的GitHub項目頁面

這裏上的幫助來解決,這是解決

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; 
}