Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an implementation somewhere of the yellow screen of death?

Tags:

.net

asp.net

In ASP.NET when you are in DEBUG mode and something fails you get a the famous yellow screen of death.

It shows that there was a Server Error in <Location> Application, provides a description, exception details, source file and stack trace.

I would like to extend this error page to include some extra information.

  • Is there an "open source" implementation of the yellow screen of death?
  • Is there a way to extend the built-in yellow screen of death?
like image 505
Sam Saffron Avatar asked Sep 05 '11 05:09

Sam Saffron


3 Answers

The error page formatting is done by System.Web.ErrorFormatter and its subclasses, which unfortunately are internal. You can grab the HTML and modify it if you like using HttpException.GetHtmlErrorMessage(). But I'd be inclined to do as other commenters have suggested and use Server.GetLastError and format it myself.

If so - please ensure you HtmlEncode the error message output to mitigate XSS and ensure your production sites don't display any information about the error (as this was the attack vector for the ASP.NET padding oracle decryption attack in 2010).

like image 144
Duncan Smart Avatar answered Nov 16 '22 08:11

Duncan Smart


This page seems to have the info you're looking for.

http://www.asp.net/hosting/tutorials/processing-unhandled-exceptions-cs

Essentially, when an exception bubbles up to to the runtime it gets wrapped in an System.Web.HttpException (This was wrong. At least I didn't see this behavior in MVC 3).

I'd think you can extend that class and override GetHtmlErrorMessage to return whatever extra data you want.

Update: Well, with a little experimentation it appears I'd be wrong. BUT there is a workaround...

You can write the info from the exception in any manner you choose then clear the error and you'll have what you want returned.

Something like this...

protected void Application_Error(object sender, EventArgs e)
{
    var context = HttpContext.Current;
    var error = context.Server.GetLastError();
    context.Response.Write(error.Message);
    context.Response.Write("<br /><br />");
    context.Response.Write(error.StackTrace);
    context.Response.Write("<br /><br />");
    context.Response.Write("Hello World");
    context.Server.ClearError();
}
like image 4
Jason Punyon Avatar answered Nov 16 '22 06:11

Jason Punyon


If you are using custom error pages, I believe you can get the last error with HttpContext.Current.Server.GetLastError(); I'm not sure if there are any custom pages out there. But the content of the YSOD should be available from the context of the request.

like image 1
Matt Phillips Avatar answered Nov 16 '22 06:11

Matt Phillips