我正在通过电子邮件发送来自global.asax的未处理的异常详细信息.如何获取未处理异常的aspx文件或程序集文件的路径和/或文件名.
在我开发和测试时,此信息显示在异常的堆栈跟踪中.当我将global.asax部署到生产环境时,此信息不再显示在堆栈跟踪中.
有没有办法在Global.asax中构建我的MailMessage对象时获取此信息?
谢谢
如果这是一个ASP.NET应用程序,标签建议它,你应该能够做这样的事情...... ctx.Request.Url.ToString()会给你发生错误的文件名.
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"); }