Search code examples
asp.neterror-reportingerror-loggingyellow-screen-of-death

Can the ASP.NET Yellow Screen of Death (YSOD) be generated on demand or captured?


We'd like to just capture the YSOD output to use in an erorr reporting email, from a Global.asax error handler, for instance. Is there any way of leveraging the built-in ysod generator?


Solution

  • Yes there is a way that you can do this.

    In the Application_Error event in the global.asax file, get the last exception as an System.HttpUnhandledException. Your code will look like this:

    var lastException = Server.GetLastError() as HttpUnhandledException;
    string Ysod = lastException.GetHtmlErrorMessage();
    // your call to emailing routine follows
    

    I agree with other people's comments. You can also do this with ELMAH.