I have web application that in some pages I use Ms Ajax (Script Manager,Update Panel,...)
. In these pages I can't use compression because it conflicts with *.axd
files.
How I can compress specific pages in my web application?
I have web application that in some pages I use Ms Ajax (Script Manager,Update Panel,...)
. In these pages I can't use compression because it conflicts with *.axd
files.
How I can compress specific pages in my web application?
Have you tried HTTP compression (either dynamic and/or static content) via IIS 7, that will compress all the data that is communicated between the client and the server.
http://technet.microsoft.com/en-us/library/cc771003%28WS.10%29.aspx
I would personally use an HTTP module to compress .axd files.
There is an example of one here...
this is may be useful for you this accepts deflate and gzip compression
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string acceptEncoding = app.Request.Headers["Accept-Encoding"];
Stream prevUncompressedStream = app.Response.Filter;
if (!(app.Context.CurrentHandler is System.Web.UI.Page ||
app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler") ||
app.Request["HTTP_X_MICROSOFTAJAX"] != null)
return;
if (acceptEncoding == null || acceptEncoding.Length == 0)
return;
acceptEncoding = acceptEncoding.ToLower();
if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
{
// deflate
app.Response.Filter = new DeflateStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
}
else if (acceptEncoding.Contains("gzip"))
{
// gzip
app.Response.Filter = new GZipStream(prevUncompressedStream,
CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
}
I use a Http module to handle my compression. I am unable to use the new IIS compression for one of my sites since it is on shared hosting and they have not enabled IIS compression. I also have a custom web.config section in which i can exclude specific file paths as in:
If you want the code for module let me know. I can post it too. One class actually does the compression while i use 3 other classes to handle the custom web.config section.
Just specify the pages to be excluded and they are not compressed.
My compression module is below: