I am running into some problem, I created a type that I am using as a HTTPHandler for aspx in my web.config file, the code..
<add path="*.aspx" verb="*" type="myHandler"></add>
The cs page is
public class myHandler : IHttpHandler
{
public void ProcessRequest(System.Web.HttpContext context)
{
// check if client browser can accept gzip encoding
string AcceptEncoding = context.Request.Headers["Accept-Encoding"];
if (!string.IsNullOrEmpty(AcceptEncoding) && AcceptEncoding.Contains("gzip"))
{
// if yes, apply it
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
context.Response.AddHeader("Content-Encoding", "gzip");
}
// don't do anything else, just let the default page handling work
}
public bool IsReusable
{
get { return false; }
}
}
As you can see, I am checking if the client accepts a gzip encoding, if yes, add it, and let the default process handle…
BUT the response I am getting is..
XML Parsing Error: no element found
Location: http://localhost:49903/Masters/Default.aspx
Line Number 1, Column 1:
^
every single page is returning this error? I am guessing that after I handled the request in my handler, it is somehow clearing everything else or something related.
Firebug shows the following..
Response Headers
Cache-Control private
Connection Close
Content-Encoding gzip
Content-Length 0
Date Sat, 06 Oct 2012 13:14:50 GMT
Server ASP.NET Development Server/10.0.0.0
X-AspNet-Version 4.0.30319
Request Headers
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Cookie ASP.NET_SessionId=1wfoaqta3mosntii1c3ual1i; .ASPXAUTH=D41BBDC2CCF15048BB5A345EBBFBC63EAE35FD37E2F1F170C1D68495477889A989353D4EB30F2B9A723F83C21293A47478B654A1BD2453BCF032DC539427EA0E519D2FEE70DB7660F00AA90E159633C4
Host localhost:49903
Referer http://localhost:49903/Masters/Default.aspx
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1
Request Headers From Upload Stream
Content-Length 8241
Content-Type multipart/form-data; boundary=---------------------------2995119424827
So, from what I am guessing, I would like to know is there a way that after I have handled the page my way, I can do something like base.ProcessRequest(). I know its not possible, because I am implementing a interface and not deriving from a class, but I wanna know, how can I let the asp.net engine process the page after am I done with mine?
NB This question is not about implementing gzib encoding, I know I can set it in web config, at each page, in IIS, make a static function in a utility class and call it, and many other things. But again, please don’t answer that I could use a different way to implement this gzip encoding, I know I can, what I am concerned is how can I let asp.net do its default handling (or whatever that may mean) after I am done with my custom handling?
You follow the wrong path. The handler you try to use is for make a totally different way for processing some kind of files ending in a different extensions, by adding the
.aspxthen you handle that page and not permit the asp.net processing the pages at all.What you should do is to make an
httpModule, eg a class like:and on web config:
or even more simple, on
global.asaxmake atApplication_BeginRequestthe gZip