Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3 compression filter causing garbled output
    primarykey
    data
    text
    <p>So, I have a custom attribute called CompressAttribute which is set up as a global filter in global.asax. It uses reflection to examine the return type of the current action method and if it is "ViewResult" it compresses the output using either GZip or Deflate. It works just fine except if a page throws a 500 Server Error. If an error is encountered, instead of displaying the .NET error page, I get a bunch of this:</p> <p>��������`I�%&amp;/m�{J�J��t��</p> <p>Apparently it's attempting to encode the 500 Server Error page which is causing problems. What's the best way to handle this?</p> <p>Here's the filter code:</p> <pre><code>public override void OnActionExecuting(ActionExecutingContext filterContext) { MethodInfo actionMethodInfo = Common.GetActionMethodInfo(filterContext); if (GetReturnType(actionMethodInfo).ToLower() != "viewresult") return; HttpRequestBase request = filterContext.HttpContext.Request; string acceptEncoding = request.Headers["Accept-Encoding"]; if (string.IsNullOrEmpty(acceptEncoding)) return; acceptEncoding = acceptEncoding.ToUpperInvariant(); HttpResponseBase response = filterContext.HttpContext.Response; if (acceptEncoding.Contains("GZIP")) { response.AppendHeader("Content-encoding", "gzip"); response.Filter = new WebCompressionStream(response.Filter, CompressionType.GZip); } else if (acceptEncoding.Contains("DEFLATE")) { response.AppendHeader("Content-encoding", "deflate"); response.Filter = new WebCompressionStream(response.Filter, CompressionType.Deflate); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload