mostlylucid

scott galloway's personal blog...
posts - 911, comments - 723, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

Catching all errors in an ASP.NET application

Okay, I realise that probably everyone and his / her mother knows this already, but if you want to log ALL errors in an ASP.NET application, the simplest way I've found to do it is in the Global.asax.cs (or whatever codebehind)...simply do this:
protected void Application_OnError(object sender, EventArgs e)
		{
			Exception ex = Server.GetLastError();
			if ( ex is HttpException )
			{
				if (((HttpException)ex).GetHttpCode() == 404)
					return;
			}     
			ExceptionManager.Publish(ex);

		}
In this instance, ExceptionManager is the Microsoft Exception Manager application block...you can (and really should) use this in conjunction with CustomError. The reason I do it here is that I prefer to make my error page flat html...just in case something really bad has happened and an active error page would cause an error itself :-) Just thought, I'll post up some code which emails you errors using the EMAB...

Print | posted on Wednesday, September 17, 2003 9:30 PM | Filed Under [ ASP.NET ]

Comments have been closed on this topic.

Powered by: