Phil Winstanley's Error Reporting and the Trace in ASP.Net 2.0

We've been using Phil Winstanley's ASP.Net WebException handler for a while now it's great (see http://weblogs.asp.net/plip/archive/2004/04/17/114984.aspx) the problem with it was that we couldn't get access to the Trace in ASP.Net 1.1. Doug and I spoke with Phil about it but at the time there wasn't a solution however he did say he thought there may be with the emergance of ASP.Net 2.0 (this was a few months before it was due to be released).

Now we're working in 2.0 on a regular basis I thought I'd give it a go and think I have a solution (though quite how reliable it is I'm not 100% sure). The fix is to tap into the current HttpContext and "switch" the trace's output on and then off before and after handling the exception and voila!

Here's my solution:

TraceContext t = HttpContext.Current.Trace; t.IsEnabled = true;WebException WE = newWebException(); WE.CurrentException = Server.GetLastError(); WE.Handle(); t.IsEnabled = false;

Subscribe to TSD

Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
jamie@example.com
Subscribe