[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

IIS - Application_OnError firing twice

Posted on 2008-11-11
5
Medium Priority
?
269 Views
Last Modified: 2012-05-05
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);
        }
0
Comment
Question by:richardsimnett
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 2000 total points
ID: 22938458
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
 

Author Comment

by:richardsimnett
ID: 22945449
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
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 22947006
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
 

Author Comment

by:richardsimnett
ID: 22947205
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
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 22956956
Hi richardsimnett,
You're welcome.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question