using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Web;
namespace MSDN.Demo.Whidbey.Compression
{
public class HttpCompressionModule : IHttpModule
{
public HttpCompressionModule()
{
}
void IHttpModule.Dispose()
{
}
void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
//
// Get the application object to gain access to the request's details
//
HttpApplication app = (HttpApplication)sender;
//
// Accepted encodings
//
string encodings = app.Request.Headers.Get("Accept-Encoding");
//
// No encodings; stop the HTTP Module processing
//
if (encodings == null)
return;
if (ShouldCompress(app.Request.Url.ToString()))
{
//
// Current response stream
//
Stream baseStream = app.Response.Filter;
//
// Find out the requested encoding
//
encodings = encodings.ToLower();
if (encodings.Contains( "gzip" ))
{
app.Response.Filter = new GZipStream( baseStream, CompressionMode.Compress );
app.Response.AppendHeader( "Content-Encoding", "gzip" );
#if DEBUG
app.Context.Trace.Warn( "GZIP compression on" );
#endif
}
else if (encodings.Contains( "deflate" ))
{
app.Response.Filter = new DeflateStream( baseStream, CompressionMode.Compress );
app.Response.AppendHeader( "Content-Encoding", "deflate" );
#if DEBUG
app.Context.Trace.Warn( "Deflate compression on" );
#endif
}
}
}
private bool ShouldCompress( string s )
{
string str = s.ToLower();
if ((str.Contains( ".aspx" )) || (str.Contains( ".htm" )))
{
return true;
}
else
{
return false;
}
}
}
}
Hello
Here is misc question:
In VS 2003 I used defined events in InitializeComponent
NewsList.ascx
private void InitializeComponent()
{
//event for usercontrol
this.PreRender +=new EventHandler(NewsList_PreRender);
//event for telerik control
RadToolbar1.OnClick += new Telerik.WebControls.RadToolbar.OnClickDelegate(RadToolbar1_OnClick);
}
How (where) do I define those two event handlers in VS 2005 in partial class (I always use partial class)?
I would like a practical example of the above code! Thank you for help!
Lp
Sebastijan