IIS - Application_OnError firing twice

Ok guys.  please help me out with this.  I am trying to log errors to a DB table from inside an ASP.Net app written in C#.  my problem is that it logs the same error twice.  the second log entry is about 400 ms behind the first.  the server.transfer destination /error/error.aspx page has no functionality at the moment.

is there something about the way Application_Error gets called that i am ignorant of?

I am running the following function inside the global.asax.cs code behind.  (the call to insErrorLog() just runs a sproc to the DB that seems to be working.)

void Application_Error(object sender, EventArgs e)
    {
        try
        {
            // Code that runs when an unhandled error occurs
            Exception ex = Server.GetLastError().GetBaseException();


            //loop through the queryString's name value collection to build l_szQueryString
            string l_szQueryString = "?";

            foreach (string key in Request.QueryString.Keys)
            {
                l_szQueryString = l_szQueryString + key + "=" + Request.QueryString[key] + "&";
            }

            //strip out trailing "&"
            if (l_szQueryString.Length > 0)
            {
                l_szQueryString = l_szQueryString.Remove(l_szQueryString.Length - 1);
            }

            insErrorLog(Request.Url.ToString(), ex.StackTrace, ex.Message, l_szQueryString);

            Server.ClearError();

            Server.Transfer("/error/error.aspx");
           
        }
        catch(Exception ex)
        {
            //do nothing cause you cant log it anyway
            Context.Response.Write(ex.Message + "<br><br>" + ex.StackTrace);

           
            //Server.Transfer("/error/error.aspx");
        }

    }
//---------------------------------------------------


I am forcing errors by using the following code on a test page:

protected void Page_Load(object sender, EventArgs e)
        {
            //throw new Exception("testError");
            int i = 0;
            Response.Write(10 / i);
        }
richardsimnettAsked:
Who is Participating?
 
David H.H.LeeConnect With a Mentor Commented:
Hi richardsimnett,
Try change this code:
Change to Context.ClearError instead of Server.ClearError();

Please refer following practise as well:
http://www.aspnetpro.com/newsletterarticle/2004/07/asp200407dk_l/asp200407dk_l.asp
0
 
richardsimnettAuthor Commented:
x_com: thanks for the link to the page.
it gave me some new avenues to test this thing against.

however, i have just discovered that the double loading is actually occurring on the client side.  i took a peak in the IIS logs and the page is getting called twice from the browser.  odd thing is that it only happens in firefox, when i run internet explorer against it i only get one call and one error row in the DB table.

any thoughts on why this may be happening?
0
 
David H.H.LeeCommented:
Hi richardsimnett,
There are a lot of possibility of getting errors based on browser compatiability issue. Can you post what errors that happend in firefox but not in IE as mentioned? Perhaps we can check from mentioned for further investigation?
0
 
richardsimnettAuthor Commented:
i just figured it out.  and man, do i hate web programming.  everytime i touch it, i regret it.

the problem is my copy of firefox (v3.0.3) and some combination of the noScript, flashblocker, and firebug plugins are conspiring to load the page twice.  my friend's firefox v3.0.3 has no such issues.

thanks for your help.  just knowing that you would be looking at my code caused me to get more serious about putting the calipers on this thing and start tracing all the http calls and examining it more thoroughly.
0
 
David H.H.LeeCommented:
Hi richardsimnett,
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.