use HttpCompression show unreadable characters
-
Sunday, December 05, 2010 11:06 AM
I want to use httpcompression in may asp.net 3.5 website and IIS 7.5 Server,so I Create a ClassLibrary(HttpCompression) and write this codes:
namespace Behsaman.Web { public class HttpCompression : IHttpModule { #region IHttpModule Members public void Dispose() { } void IHttpModule.Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); } void context_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; string encodings = app.Request.Headers.Get("Accept-Encoding"); if (!app.Request.RawUrl.Contains(".aspx") || HttpContext.Current.Request["HTTP_X_MICROSOFTAJAX"] != null || HttpContext.Current.Request["http_x-microsoftajax"] != null || HttpContext.Current.Items["hasBeenCompressed"] !=null || string.IsNullOrEmpty(encodings)) return; encodings = encodings.ToLower(); if (encodings.Contains("deflate")) { app.Response.Filter = new DeflateStream(app.Response.Filter, CompressionMode.Compress); app.Response.AppendHeader("Content-Encoding", "deflate"); } else if (encodings.Contains("gzip")) { app.Response.Filter = new GZipStream(app.Response.Filter, CompressionMode.Compress); app.Response.AppendHeader("Content-Encoding", "gzip"); } else { return; } app.Response.Cache.VaryByHeaders["Accept-encoding"] = true; HttpContext.Current.Items["hasBeenCompressed"] = true; } #endregion } }
and then add this dll to my website refrences. then I write this code in web.config
# < system.webServer > # ......... # < modules > # ........ # < add name = "HttpCompression" type = "Behsaman.Web.HttpCompression" /> # </ modules > # ............. # </ system.webServer >
when I browse a page I see unreadable characters like this:�`I�%&/m�{
I see firebug and check Response Header :
In the Content-Encoding row you can see a comma after defalte word, is it normal?How can I fix my problem?Cache-Control privateContent-Type text/html; charset=utf-8Content-Encoding deflate,Server Microsoft-IIS/7.5X-AspNet-Version 2.0.50727X-Powered-By ASP.NETDate Sun, 05 Dec 2010 08:08:13 GMTContent-Length 62877- Moved by Kevin RemdeMicrosoft Employee Monday, February 28, 2011 12:27 PM (From:IT Management Planning and Technology)

