Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Debugging and global.asax

$
0
0

I have some code in the Global.asax Application_Error method that sends me an email with all the details of the error so it helps me fix errors find by users.

When I am debugging I dont want the webpage to send me the email though, I want Visual Studio to get the focus and point me to the line that breaks the webpage, that is the normal behavior when you dont have anything defined in Application_Error.

To do that I simply comment the code inside Application_Error when debugging and uncomment it when I want to deploy.

The problem is that I always forget to comment or uncomment, I want an automatic way of determing whether to send the email or not.

I tried adding this at the beggining of Application_Error

            if (HttpContext.Current.IsDebuggingEnabled)
            {
                return;
            }

But the problem is that when debugging I wont get to the line that triggered the exception, I would get the asp.net ugly yellow error page directly.

I tried to use precompiler directives like

#if DEBUG
#else
  // send email
#endif

But then the code between the # symbols is not checked by the compiler! I can have syntax erros and it compiles anyways, I dont want that.

Any idea?

Thanks!


Viewing all articles
Browse latest Browse all 3509

Trending Articles