2012-05-04 7 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; 
}