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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David H.H.LeeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.