ASP.NET 黄屏死机 (YSOD) 可以按需生成或捕获吗?

发布于 2024-07-21 00:42:33 字数 84 浏览 14 评论 0原文

例如,我们只想捕获 YSOD 输出以在错误报告电子邮件中使用,例如来自 Global.asax 错误处理程序。 有没有办法利用内置的 ysod 生成器?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

说谎友 2024-07-28 00:42:35

你听说过埃尔玛吗? 它可能会为您提供您真正想要的所有功能...

这是一篇博客文章,对此进行了一些解释: http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx

Have you heard of ELMAH ? It might give you all the features you really want...

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

娇俏 2024-07-28 00:42:35

您应该查看 ELMAH 它会自动执行您所要求的操作。

You should check out ELMAH it does what you are asking automatically.

神爱温柔 2024-07-28 00:42:35

我想说的是,一般来说,你不希望用户体验 YSOD。 这是我之前在网络应用程序中放置的东西,用于捕获错误,然后向用户提供更优雅的错误页面......

protected void Application_Error(object sender, EventArgs e)
{
    MailMessage msg = new MailMessage();
    HttpContext ctx = HttpContext.Current;

    msg.To.Add(new MailAddress("[email protected]"));
    msg.From = new MailAddress("[email protected]");
    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");
}

I would say in general, you do not want the user to experience the YSOD. This is something I've put in web apps before to capture the error and then allow for a more graceful error page to the user...

protected void Application_Error(object sender, EventArgs e)
{
    MailMessage msg = new MailMessage();
    HttpContext ctx = HttpContext.Current;

    msg.To.Add(new MailAddress("[email protected]"));
    msg.From = new MailAddress("[email protected]");
    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");
}
苏大泽ㄣ 2024-07-28 00:42:35

每当应用程序中发生未处理的异常时,就会触发 Global.asax 文件中的 Application_Error 事件。 您可以使用 Server.GetLastError() 方法获取最后发生的异常。

同样,您可以通过在 web.config 文件的 customErrors 部分下的 web.config 中指定来创建自己的自定义错误页面。 通过指定默认文件,当异常路由到那里时,您可以执行任何自定义编码。

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

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

绝不放开 2024-07-28 00:42:33

我会研究ELMAH(ASP.NET 的错误日志模块和处理程序)

ELMAH(错误记录模块和
Handlers)是一个应用程序范围的错误
完全的日志记录设施
可插拔。 可以动态添加
到正在运行的 ASP.NET Web 应用程序,
甚至所有 ASP.NET Web 应用程序
在机器上,无需任何
重新编译或重新部署。

一旦 ELMAH 被扔进
运行 Web 应用程序并配置
适当地,你会得到以下内容
设施无需改变任何一个
您的代码行:

  • 记录几乎所有未处理的异常。
  • 用于远程查看记录异常的整个日志的网页。
  • 用于远程查看任何登录者的完整详细信息的网页
    例外。
  • 很多情况下,可以回顾一下原来的黄屏死机
    ASP.NET 为给定的生成
    异常,即使使用 customErrors 模式
    已关闭。
  • 每个错误发生时的电子邮件通知。
  • 日志中最后 15 个错误的 RSS 提要。

I would look into ELMAH (Error Logging Modules and Handlers for ASP.NET):

ELMAH (Error Logging Modules and
Handlers) is an application-wide error
logging facility that is completely
pluggable. It can be dynamically added
to a running ASP.NET web application,
or even all ASP.NET web applications
on a machine, without any need for
re-compilation or re-deployment.

Once ELMAH has been dropped into a
running web application and configured
appropriately, you get the following
facilities without changing a single
line of your code:

  • Logging of nearly all unhandled exceptions.
  • A web page to remotely view the entire log of recoded exceptions.
  • A web page to remotely view the full details of any one logged
    exception.
  • In many cases, you can review the original yellow screen of death
    that ASP.NET generated for a given
    exception, even with customErrors mode
    turned off.
  • An e-mail notification of each error at the time it occurs.
  • An RSS feed of the last 15 errors from the log.
如若梦似彩虹 2024-07-28 00:42:33

是的,有一种方法可以做到这一点。

在 global.asax 文件的 Application_Error 事件中,获取最后一个异常作为 System.HttpUnhandledException。 您的代码将如下所示:

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

我同意其他人的评论。 您也可以使用 ELMAH 来完成此操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文