Compression - need help asap!!!

R

Roshawn

Hi,

I've created a little compression class to be used by asp.net. Simple really, no heavy code anywhere. Have a looksee (it's
in VB.NET):

#Region "Imports"
Imports System
Imports System.IO
Imports System.IO.Compression
Imports System.Web
#End Region

Public Class HttpCompressionModule
Implements IHttpModule

Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub

Public Sub HttpCompress(ByVal app As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler app.BeginRequest, AddressOf Me.HttpCompress_BeginRequest
End Sub

Public Sub HttpCompress_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim app As HttpContext = HttpContext.Current
Dim encodings As String = app.Request.Headers.Get("Accept-Encoding")
If encodings Is Nothing Or encodings = "" Then
Return
End If
Dim baseStream As Stream = app.Response.Filter
If LCase(encodings).Contains("gzip") Then
app.Response.Filter = New GZipStream(baseStream, CompressionMode.Compress)
app.Response.AppendHeader("Content-Encoding", "gzip")
app.Trace.Warn("GZip Compression On")
ElseIf LCase(encodings).Contains("deflate") Then
app.Response.Filter = New DeflateStream(baseStream, CompressionMode.Compress)
app.Response.AppendHeader("Content-Encoding", "deflate")
app.Trace.Warn("Deflate Compression On")
End If
End Sub
End Class

OK. See, I told you it was simple. It works as expected. Well...not exactly. See, my web pages use a .css file and for
some reason beyond my knowledge, this code compresses it as well. When using the WebDeveloper extension in Firefox, I get a
bunch of garbage.

Is there anyway to prevent the compression of .css and other files? If so, where do I place it in my code?

Thanks,
Roshawn
 
R

Roshawn

Further testing reveals that my .css file gets compressed randomly. Strange behavior...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top