当我在操作上使用了CompressFilter且出现错误时,我的ExceptionHandling没有被触发。请求没有返回任何响应。如果我移除Compress filter,那么它会正常返回错误数组。如何跳过压缩过滤器并让其第二次触发?
控制器操作
[HttpPost, CompressAttribute]
public virtual ActionResult Builder()
Global.asax
GlobalConfiguration.Configuration.Filters.Add(new ExceptionHandlingAttribute());
CompressFilter
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class CompressAttribue : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var encodingsAccepted = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(encodingsAccepted)) return;
encodingsAccepted = encodingsAccepted.ToLowerInvariant();
var response = filterContext.HttpContext.Response;
if (encodingsAccepted.Contains("gzip"))
{
response.AppendHeader("Content-encoding", "gzip");
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
}
else if (encodingsAccepted.Contains("deflate"))
{
response.AppendHeader("Content-encoding", "deflate");
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
}
}
}