ASP.NET Debugging Tip with Application_Error
By Peter Bromberg
Often when you are debugging an ASP.NET application you find that something you "think" should work doesn't work, or you get a blank page. Wiring up the unhandled exception handler in Global.asax.cs (vb) can help solve these problems.
Here is some sample code from Global.asax.cs:
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
// SET A BREAKPOINT ON THE NEXT LINE AND LEAVE IT THERE.
System.Diagnostics.Debug.WriteLine( ex.ToString() );
Server.ClearError();
}
Application_Error is the ASP.NET equivalent of the unhandled exception "holder
of last resort". When something in a page goes wrong, if you have the above
code wired up, you'll find out about it right away.
This simple technique can save you hours of frustration. Try it!
ASP.NET Debugging Tip with Application_Error (1098 Views)