C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

how to implement http compression in .net


Posted Date: 06 Nov 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Kapil DhawanMember Level: Gold    
Rating: 1 out of 5Points: 10



There are 2 types of http Compressions

1). Gzip and
2). Deflate

As per my knowledge Gzip is the default one.( but please conform too)

to implement this, we just need to import these classes

1). System.IO;
2). System.IO.Compression;


To implement this functionality to your website,
add a global file and under the Application_BeginRequest use this code,



HttpApplication oApp = (HttpApplication)sender;
string acceptEncoding = oApp.Request.Headers["Accept-Encoding"];
Stream prevUncompressedStream = oApp.Response.Filter;

if (acceptEncoding == null || acceptEncoding.Length == 0)
return;

acceptEncoding = acceptEncoding.ToLower();

if (acceptEncoding.Contains("gzip"))
{
// gzip
oApp.Response.Filter = new GZipStream(prevUncompressedStream,
CompressionMode.Compress);
oApp.Response.AppendHeader("Content-Encoding",
"gzip");
}
else if (acceptEncoding.Contains("deflate"))
{
// defalte
oApp.Response.Filter = new DeflateStream(prevUncompressedStream,
CompressionMode.Compress);
oApp.Response.AppendHeader("Content-Encoding",
"deflate");
}





now the http compression will be automatically work for your asp.net pages.

you can check the sites here for http Compression,
but it not work for local.

http://www.port80software.com/surveys/top1000compression/#checkyoursite


Please correct me,
if i am wrong some where

have a good learning.


If we use gzip for dotnetspider.com,
68.0% traffic can be saved.
to check this, go to the same URL i have given above.






Responses

Author: thebarrett27    04 May 2009Member Level: Bronze   Points : 0
nice article.
thanks


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Http compression  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Adding field to a document library in sharepoint.
Previous Resource: Caching in ASP.Net
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use