为了实现这一目标,您应该做的所有事情都是实施新的IActionFilter
或IAuthorizationFilter
类似以下的:
public class CheckAccessFilter : FilterProvider, IActionFilter, IAuthorizationFilter {
public void OnActionExecuting(ActionExecutingContext filterContext) {
// here you can check the incoming request, and how the system will deal with it,
// before executing the action
}
public void OnActionExecuted(ActionExecutedContext filterContext) {
}
public void OnAuthorization(AuthorizationContext filterContext) {
// here you can authorize any request
}
}
但是,如果您只想根据内容项(例如:Widgets、Pages、Projections)进行授权,您可以实现IAuthorizationServiceEventHandler
:
public class IPAuthorizationEventHandler : IAuthorizationServiceEventHandler {
public void Checking(CheckAccessContext context) {
}
public void Adjust(CheckAccessContext context) {
}
public void Complete(CheckAccessContext context) {
}
}
实现此方法的最佳示例是SecurableContentItemsAuthorizationEventHandler
,您可以在Orchard.ContentPermissions
module.