Sam Saffron
Sam Saffron

Reputation: 131112

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

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.

Upvotes: 15

Views: 2232

Answers (4)

Stefan Steiger
Stefan Steiger

Reputation: 82146

Yes there is.

See here:
http://www.oschina.net/code/explore/mono-2.8.1/mcs/class/System.Web/System.Web/HttpException.cs

It's from the source code of mono (.NET for Linux), in versions < 2.10 (that is to say 2.8). In version 2.10+, they started using templates, which makes it far more difficult to find and understand it.

Upvotes: 0

Duncan Smart
Duncan Smart

Reputation: 32058

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

Upvotes: 10

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();
}

Upvotes: 4

Matt Phillips
Matt Phillips

Reputation: 11499

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.

Upvotes: 1

Related Questions