.net - Compression in IIS 8.5 not successful, stating ALREADY_CONTENT_ENCODING -
i trying debug issue of why pages not being gzip'ed or deflated according yslow. ended enabling failed request logs on server , able see failed reason of why not compressing, thinks compressed.
dynamic_compression_not_success reason="already_content_encoding"
i have enabled dynamic , static compression in iis, have changed web.config file include following.
<httpcompression directory="%systemdrive%\inetpub\temp\iis temporary compressed files"> <scheme name="gzip" dll="%windir%\system32\inetsrv\gzip.dll" staticcompressionlevel="9" /> <dynamictypes> <add mimetype="text/*" enabled="true" /> <add mimetype="message/*" enabled="true" /> <add mimetype="application/x-javascript" enabled="true" /> <add mimetype="application/json" enabled="true" /> <add mimetype="*/*" enabled="false" /> </dynamictypes> <statictypes> <add mimetype="text/*" enabled="true" /> <add mimetype="message/*" enabled="true" /> <add mimetype="application/x-javascript" enabled="true" /> <add mimetype="application/atom+xml" enabled="true" /> <add mimetype="application/xaml+xml" enabled="true" /> <add mimetype="*/*" enabled="false" /> </statictypes> </httpcompression> <urlcompression dostaticcompression="true" dodynamiccompression="true"/>
in addition on aspx page have method call before every page (on page load) run gzip compression (this might why causing error).
this how call method page load
//compress page compression.gzipencodepage();
and method compresses page
using system; using system.collections.generic; using system.linq; using system.web; namespace initialdataentry { public static class compression { /// <summary> /// sets current page or handler use gzip through response.filter /// important: /// have call method before output generated! /// </summary> public static void gzipencodepage() { httpresponse response = httpcontext.current.response; if (isgzipsupported()) { string acceptencoding = httpcontext.current.request.headers["accept-encoding"]; if (acceptencoding.contains("deflate")) { response.filter = new system.io.compression.deflatestream(response.filter, system.io.compression.compressionmode.compress); response.appendheader("content-encoding", "deflate"); } else { response.filter = new system.io.compression.gzipstream(response.filter, system.io.compression.compressionmode.compress); response.appendheader("content-encoding", "gzip"); } } // allow proxy servers cache encoded , unencoded versions separately response.appendheader("vary", "content-encoding"); } /// <summary> /// determines if gzip supported /// </summary> /// <returns></returns> public static bool isgzipsupported() { string acceptencoding = httpcontext.current.request.headers["accept-encoding"]; string ispartial = httpcontext.current.request.headers["x-microsoftajax"]; if (!string.isnullorempty(acceptencoding) && acceptencoding.contains("gzip") || acceptencoding.contains("deflate")) //just checking see if partial page update if (string.compare("delta=true", ispartial, true) == 0) { return false; } else { return true; } else { return false; } } } }
this used work way, not sure when stopped, users realized issue pages got bloated in size , used 500k 2mb!
any appreciated.
thanks,
we had similar issue on windows 2012 r2 server; following below steps solved our problem:
Comments
Post a Comment