开发者

Generating the standard ASP.NET 'uncaught exception' page HTML from the exception itself?

开发者 https://www.devze.com 2022-12-11 04:52 出处:网络
Is it possible to generate the HTML page normally shown for an uncaught exception in ASP.NET, using an Exception object?

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 开发者_C百科put it in something like the link from a jQuery ThickBox overlay...

Thanks.


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 ().


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..
0

精彩评论

暂无评论...
验证码 换一张
取 消