开发者

Ajax framework failed to load with Gzip compression on IE only

Well, I got gzip working, but there are issues with IE. (works fine with FF and Chrome) Message: ASP.NET Ajax client-side framework failed to load. (and many other js related errors)

How can I prevent gzip compression on ie browsers ?? Other people who had similar issues enabled compression in IIS and that seems to solve the issue, but I can't do this on my discount machine...

This is what I use:

        HttpApplication app = (HttpApplication)sender;

        string acceptEncoding = app.Request.Headers["Accept-Encoding"];
        Stream prevUncompressedStream = app.Response.Filter;
        if (acceptEncoding != null && acceptEncoding.Length != 0)
        {

            acceptEncoding = acceptEncoding.ToLower();
            if (acceptEncoding.Contains("gzip"))
            {

                app.Response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
                app.Response.AppendHeader("Content-Encoding", "gzip");
            }

            else if (acceptEncoding.Contains("deflate"))
            {
                // defalte

                app.Response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.C开发者_StackOverflowompress);
                app.Response.AppendHeader("Content-Encoding", "deflate");

            }
        }


Try to compress GZip only the files that ends on aspx and left WebResource that contains the Javascript that you have problem, to compress by iis him self.

string cTheFile = HttpContext.Current.Request.Path;
string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);

if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
{
    // run your code for compression here
}

This will solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜