Error Reporting and the Trace in ASP.Net 2.0 -Code Update

I've just had it pointed out to me (and quite rightly so) by Craig that my code for enabling the trace with Phil Winstanley's WebException was a touch wrong. I was assuming that the user was (correctly imho) running the application with the trace already disabled. However correct that may be, it may not be the case so as pedantic as this is, the code snippet should really be:

TraceContext t = HttpContext.Current.Trace;
bool bCurrentState = t.IsEnabled;
t.IsEnabled = true;
WebException WE = new WebException();
WE.CurrentException = Server.GetLastError();
WE.Handle();
t.IsEnabled = bCurrentState;

Although I've adapted the code to accomodate this, I really wouldn't run production sites with the trace enabled as this is not only a performace hit but quite a security issue!

Author

Tim

comments powered by Disqus