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.
You could check to see if the request is to localhost:
// Check if the request was made to localhost.
String urlBegining = Request.Url.ToString().Substring(0, 16);
if (urlBegining != "http://localhost")
{
// Add the code to send an email with error information here...
}
My problem is not figuring out if I am debugging or not. The problem is that if I write something inside the Application_Error method, then Visual Studio or the Developer Server will no longer point to the line that triggers the error, but it will show me
an error page instead.
The behavior of the development server seems to change based on whether or not the Application_Error method is empty.
BCartolo
Member
7 Points
12 Posts
Debugging and global.asax
Dec 07, 2012 02:45 PM|LINK
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
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!
jprochazka
Contributor
4992 Points
748 Posts
Re: Debugging and global.asax
Dec 07, 2012 03:14 PM|LINK
You could check to see if the request is to localhost:
// Check if the request was made to localhost. String urlBegining = Request.Url.ToString().Substring(0, 16); if (urlBegining != "http://localhost") { // Add the code to send an email with error information here... }BCartolo
Member
7 Points
12 Posts
Re: Debugging and global.asax
Dec 07, 2012 07:04 PM|LINK
My problem is not figuring out if I am debugging or not. The problem is that if I write something inside the Application_Error method, then Visual Studio or the Developer Server will no longer point to the line that triggers the error, but it will show me an error page instead.
The behavior of the development server seems to change based on whether or not the Application_Error method is empty.
But thanks anyways!
Angie xu - M...
All-Star
20268 Points
1726 Posts
Microsoft
Re: Debugging and global.asax
Dec 14, 2012 01:30 AM|LINK
Hi BCartolo
Please refer the tutorials below, I think you will be helpful for you to troubleshoot better,
Breakpoint in global.asax is never reached by debugger in VS
http://www.codeproject.com/Articles/107240/Breakpoint-in-global-asax-is-never-reached-by-debu
Is it better to use HttpContext.Current.IsDebuggingEnabled or #if DEBUG?
http://stackoverflow.com/questions/6871458/is-it-better-to-use-httpcontext-current-isdebuggingenabled-or-if-debug
Kind regards
Feedback to us
Develop and promote your apps in Windows Store
BCartolo
Member
7 Points
12 Posts
Re: Debugging and global.asax
Dec 14, 2012 04:46 PM|LINK
Thanks, but I didnt find anything useful in the links you recommended.
BCartolo
Member
7 Points
12 Posts
Re: Debugging and global.asax
Jan 07, 2013 06:07 PM|LINK
I found the source of the problem!!! I was debugging using google chrome, I changed to explorer and the debugger gets the focus now!
Thanks everybody for your answers