views:

100

answers:

2

Hi all.

Is it possible to generate the HTML page normally shown for an uncaught exception in ASP.NET, using an Exception object?

I have an app that catches an exception in Global.asax -> Application_Error, and does a Server.Transfer() to our pretty general-error page. I have an #if DEBUG flag that's pulling out the Exception from Server.GetLastError() and is currently custom formatting it.

But now I'm curious if I can get the HTML normally given, and put it in something like the link from a jQuery ThickBox overlay...

Thanks.

+1  A: 

Don't know if you can actually get ACCESS to the generated HTML while catching the error, but you already have all the information you neeed in the Exception object, so you can easily generate an identical page:

  • It's simply a matter of generating an error, then View->Source in IE .. copy + paste in your error page, then replace the error text bits. Basically you use the StackTrace and the Message properties of the exception..
Radu094
Oh, I'm aware the exception has all I need - I'm currently rendering a custom formatting of it.I'm curious if I can get MS's version in a single method call...
Overflew
+1  A: 

There are two options:

  • The exception is an HttpException: call GetHtmlErrorMessage() and get the HTML.
  • The exception is not an HttpException: call new HttpException (exc.Message, exc).GetHtmlErrorMessage ().
Gonzalo
+ a touch-up, if anyone has issues - http://www.groupsrv.com/dotnet/about217784.html
Overflew
Ah, yes. That problem might happen if HttpContext.Current is not set for the thread.
Gonzalo