views:

285

answers:

3

Hi there,

I have a strange issue where i have a a HttpHandler having its ProcessRequest() event firing twice.

i have nothing else in the class except a pointer to a static method so i'm lost.

I have done some googling to no avail even thought it appears a few people are having similar issues:

Code:

    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        Common.Tracker.TrackPageView(context);
    }
A: 

It looks like you are attempting to track a page view; could something on the client be causing the page/handler to get called twice? I have seen similar behavior in the past when the html sent to the browser contained an img tag without the src attribute. This only happened in FireFox, but was causing the page to get called twice. Suggestions: See if there are any images without src tags; use Fiddler or FireBug to inspect the http traffic and ensure that you are not inadvertently calling the handler twice. More details would also be helpful. Hope this helps.

David A Moss
I am directly calling the handler. I intend to have it displayed as a tracking pixel but havent got that far. i am simply calling it in a browser. it then streams a gif file to the browser. this is working fine, it just fires the method twice??
Doug
+1  A: 

Scrap this.

I have been testing in firefox and this ONLY happens when i directly call the handler.

If i have the handler set up as an image src this doesn't happen.

additionally in IE this doesn't happen - it is firefox only.

i thought it could be my extensions (specifically firebug or YSLOW), so i manually disabled them one by one and it was still happening so i have no idea but firefox makes two calls to a page.

maybe it is similar to this old post as i'm returning a GIF as the content type: http://www.hanselman.com/blog/InternetExplorerAndTheMagicOfMicrosoftKBArticleQ293792.aspx

hope this helps someone as that is a couple of hours i'll never get back...

Doug
A: 

Hi Doug,

Did you find a sollution for this problem? I am having the same problem, playing arround with it for almost a full day now without any progress... What I am trying to do is to show pictures from a database while making it look like they are just physical e.g. Picture1.jpg instead of ShowPicture.aspx?PictureId=1. This all works without a problem aslong as I embed the picture in a form with a img tag. When I want to show just the picture e.g. (www.mysite.com/Picture1.jpg) FireFox will fire the handler multiple times while no problem with IE.

Handler

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "image/jpeg"

    // retrieve picture in SqlDataReader myReader
    context.Response.OutputStream.Write((byte[])myReader["FileData"], 0, ((byte[])myReader["FileData"]).Length);
}

web.config

<add verb="GET" path="*.jpg" type="ViewFileHandler" validate="false"/>

I noticed; - FireFox will fire 3 times in normal situation - FireFox will fire 2 times if the url does not have the .jpg or .gif extention - FireFox will only fire once if (besides different extention) the ContentType is not set to "image/jpg" (ofcourse it won't show a picture then...)

Gerard
Still as yet have not found a solution - it appears to only affect firefox when directly calling the file.if it sits in a file refer inside a page (like an image or a swf path) firefox only calls it once, and as i was writing an image handler this was fine for me, as the images where going to be shown on a page...ie.<img src='[path to my handler]' />
Doug