Can I generate on demand or capture ASP.NET Yellow Screen of Death (YSOD)?

We would just grab the YSOD output for use in the erorr email message, for example, from the Global.asax error handler. Is there a way to use the built-in ysod generator?

+6
error-logging yellow-screen-of-death
source share
6 answers

Yes you can do it.

In the Application_Error event in the global.asax file, get the last exception as a 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 the comments of other people. You can also do this with ELMAH.

+7
source share

I would consider ELMAH (error logging modules and handlers for ASP.NET) :

ELMAH (Error Logging Modules and Handlers) is a system-wide error logging object that is fully pluggable. It can be dynamically added to the running ASP.NET web application, or even all ASP.NET web applications on the machine, without any recompilation or redeployment.

After ELMAH has been reset to run the web application and configured properly, you get the following without changing one line of your code:

  • Registration of almost all unhandled exceptions.
  • Web page to remotely view the entire log of the encoded exception.
  • A web page to remotely view full details of any registered exception.
  • In many cases, you can view the original yellow death screen that ASP.NET generated for a given exception is turned off even in customErrors mode.
  • Email notification of each error at the time it occurs.
  • RSS feed of the last 15 errors from the journal.
+9
source share

Have you heard of ELMAH? This can give you all the features you really want ...

Here is a blog post that explains this a bit: http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx

+3
source share

You have to check ELMAH , it does what you request automatically.

+2
source share

I would say, in general, you do not want the user to experience YSOD. This is what I put in web applications before grabbing the error and then allowing the user a more graceful error page ...

 protected void Application_Error(object sender, EventArgs e) { MailMessage msg = new MailMessage(); HttpContext ctx = HttpContext.Current; msg.To.Add(new MailAddress(" me@me.com ")); msg.From = new MailAddress(" from@me.com "); msg.Subject = "My app had an issue..."; msg.Priority = MailPriority.High; StringBuilder sb = new StringBuilder(); sb.Append(ctx.Request.Url.ToString() + System.Environment.NewLine); sb.Append("Source:" + System.Environment.NewLine + ctx.Server.GetLastError().Source.ToString()); sb.Append("Message:" + System.Environment.NewLine + ctx.Server.GetLastError().Message.ToString()); sb.Append("Stack Trace:" + System.Environment.NewLine + ctx.Server.GetLastError().StackTrace.ToString()); msg.Body = sb.ToString(); //CONFIGURE SMTP OBJECT SmtpClient smtp = new SmtpClient("myhost"); //SEND EMAIL smtp.Send(msg); //REDIRECT USER TO ERROR PAGE Server.Transfer("~/ErrorPage.aspx"); } 
+2
source share

The Application_Error event in the Global.asax file is fired whenever an unhandled exception occurs in the application. You can get the last exception that occurred with the Server.GetLastError () method.

Similarly, you can create your own error page by specifying it in the web.config file in the customErrors section of the web.config file. By specifying a default file, you can do any custom encoding when an exception is thrown there.

+1
source share

All Articles