Hi!
I'm using HttpModule for comression. Everything is well but client-side AJAX does not decompress response (after aynchronous request): error: "The message received from the server control could not be parsed."
Question 1: can I make AJAX to decompress asynch. responses ?
Question 2: can I make AJAX to decompress asynch.requests ?
<httpModules><addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<addname="CompressionModule"type="WebSite.CompressionModule" /></httpModules>
#region Using
using System;
using System.Web;
using System.IO;
using System.IO.Compression;
#endregion
namespace WebSite
{
///<summary>/// Compresses the output using standard gzip/deflate.
///</summary>
publicclass CompressionModule : IHttpModule{
publicvoid Init(HttpApplication context)
{
context.BeginRequest +=newEventHandler(context_BeginRequest);}
privatevoid context_BeginRequest(object sender,EventArgs e){
HttpApplication app = (HttpApplication)sender;
if (app.Request.Url.ToString().ToLower().IndexOf("aspx") < 0)return;string encodings = app.Request.Headers.Get("Accept-Encoding");
if (encodings ==null)return;Stream baseStream = app.Response.Filter;encodings = encodings.ToLower();
if (encodings.Contains("gzip")){
app.Response.Filter =new GZipStream(baseStream,CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding","gzip");}
elseif (encodings.Contains("deflate")){
app.Response.Filter =new DeflateStream(baseStream,CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding","deflate");}
}
publicvoid Dispose(){
}
}
Thank you for any help.
Andriy Zhornyk
Hi Andriy Zhornyk,
the best and practicable solution is to exclude the ajax related resources from your compression module. On the board ar some discussions about compression wirh ajax. AFAIK the most come to the same result, exclude the ajax resources from compression. In my compression module i do it win my configuration like this.
<HttpCompress compressionType="GZip"><ExcludedPathCollection><clear/><add path="WebResource.axd"/><add path="ScriptResource.axd"/><add path="*._AppService.axd"/></ExcludedPathCollection><ExcludedMimeTypeCollection><clear/><add mime="image/jpeg"/><add mime="image/gif"/><add mime="image/png"/><add mime="image/ico"/><add mime="application/binary"/></ExcludedMimeTypeCollection><ExcludedVariableCollection><clear/><add servervariable="http_x_microsoftajax"/></ExcludedVariableCollection></HttpCompress>
hope that help a little to find the right decision.
Thank you, but it's interesting for me to compress/decomress async postback data.
Is there such possibolity in MS Ajax?
That would be pretty difficult. The AJAX framework needs to be able to parse out the pipe delimited partial postback response. If it were compressed, you'd have to extend the PageRequestManager to handle that somehow.
I appreciate your answer but decompression on client is not impossible.
Have you seen "TeamPlain" solution from devBiz acquired by MS ? (web site for TFS:http://www.devbiz.com/downloads/TeamPlain-Web-2.0-RC.msi)
They managed to do it! Of course they didn't use MS Ajax but they compressed\decompressed async postbacks. The same thing I'm waiting from MS AJAX team. Because ZGipped page is very important for my customers' users with slow dialup internet...
I've been investigating MS AJAX Web.Extension source code and I think it's real to add compression\decompression features.
Is there anyone who managed this not simple task besides smart guys from devBiz?
If i understand you right is the way to go: compress(server) -> decompress(client). On callback: compress(client) -> decompress(server).
Well, i dont know enough over the architecture of the UpdatePanel to say it's possible or not. But from my point ist the only way to go a direct implementation in the UpdatPanel control or, if possible, create an adapter.
Anyway, maybe one from the ajax extension dev team is able to enlighten us about the possibility of this way.
I've faced similar situation , i am using update panel and http compression. My workarund is to not compress/decompress async postback. I just adding some additional checking like this :
if(Context.Request.Params["HTTP_X_MICROSOFTAJAX"] == null)
{
DoCompress();
}
regards ,
yose r
No comments:
Post a Comment