我拥有auth attribiute来控制对控制器的访问
public class UserLevelAccessibilityAttribute : FilterAttribute, IAuthorizationFilter
{
var baseController = filterContext.Controller as Controllers.BaseController;
var userContext = baseController.UserContext;
if (false == userContext.HasUserLevels(_levels))
{
var postData = new Dictionary<string, object>();
postData.Add("requiredLevels", string.Join(",", _levels));
filterContext.Result =
new RedirectAndPostActionResult("/Error/Unauthorized", postData);
}
}
在代码中它看起来像
[UserLevelAccessibilityAttribute(EPermissionLevel.Pricing)]
public MyContr : Controller
{
[SkipAuthorizationFromController]
public ActionResult MyAction()
{
}
}
我的问题是如何实现 SkipAuthorizationFromController 属性来跳过控制器的授权?或者我应该更改UserLevelAccessibilityAttribute实现吗?
答案 0 :(得分:1)
检查操作中是否存在任何SkipAuthorizationFromController属性。
您可以使用以下内容来执行此操作
actionContext
.ActionDescriptor
.GetCustomAttributes<SkipAuthorizationFromController>()
.Any()