I have this custom filter for compress the output of my pages:
public class EnableCompressionAttribute : ActionFilterAttribute
{
const CompressionMode compress = CompressionMode.Compress;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestBase request = filterContext.HttpContext.Request;
HttpResponseBase response = filterContext.HttpContext.Response;
string acceptEncoding = request.Headers["Accept-Encoding"];
if (acceptEncoding == null)
return;
if (acceptEncoding.ToLower().Contains("gzip"))
{
response.Filter = new GZipStream(response.Filter, compress);
response.AppendHeader("Content-Encoding", "gzip");
}
else if (acceptEncoding.ToLower().Contains("deflate"))
{
response.Filter = new DeflateStream(response.Filter, compress);
response.AppendHeader("Content-Encoding", "deflate");
}
}
}
I got the code from the book: Pro ASP.NET MVC V2 Framework (Expert's Voice in .NET).
Now I have an action method like this:
[OutputCache(Order=1, Duration=300,VaryByParam="*", VaryByContentEncoding="gzip; deflate")]
[EnableCompression(Order=0)]
public ActionResult About()
{
return View();
}
How can I ensure that the OutputCache filter is caching the compressed content? Using the "Order" parameter like in this example will be enough?
How can I see what is going on in the cache?
Cheers.
UPDATE: I have tested with Fiddler, apparently it works no matter what order you use on the filters... I get the first response with gzip encoding, and a http.302 in following requests if the client is allowed to cache it, or more http.200 with gzip encoding if just the server is allowed
Probably this is because OutputCache is the last filter by default, and there is no way to change that. May anybody confirm this?