Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 07, 2013 06:07 PM by BCartolo
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
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
// send email
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.
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...
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!
Dec 14, 2012 01:30 AM|LINK
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
Is it better to use HttpContext.Current.IsDebuggingEnabled or #if DEBUG?
Dec 14, 2012 04:46 PM|LINK
Thanks, but I didnt find anything useful in the links you recommended.
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