我有两个过滤器:
public class ValidateModelStateFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.ModelState.IsValid == false)
{
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
}
public class AuthorizeRequestAttribute : Attribute, IAuthorizationFilter
{
public bool AllowMultiple
{
get { return false; }
}
public async Task<HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
{
// TODO: validate the request
return await continuation();
}
}
第一个在Global.asax
Application_Start
方法中注册:
protected void Application_Start()
{
GlobalConfiguration.Configuration.Filters.Add(new ValidateModelStateFilter());
}
第二个添加到控制器操作中:
[HttpGet]
[AuthorizeRequestAttribute]
public string GetValue(GetValueRequest request)
{
return _service.GetValue(request.Product_Id);
}
一切正常,除了在过滤器[AuthorizeRequestAttribute]
之前执行的事实。[ValidateModelStateFilter]
我怎样才能[ValidateModelStateFilter]
在任何其他过滤器之前执行?