简体   繁体   English

在 Elmah 电子邮件中包含完整网址

[英]Include full url in Elmah Email

Currently I get an error email from ELMAH similar to the following screenshot, which is all good.目前我收到来自 ELMAH 的错误电子邮件,类似于以下屏幕截图,这一切都很好。

在此处输入图片说明

But one thing that is missing is a full url something similar to what you get from a Request.Url.ToString() (ie including domain,path and query).但缺少的一件事是一个完整的 url,类似于您从Request.Url.ToString() (即包括域、路径和查询)。 I'd like to know if there is an easy way to include the full request url which caused the error somewhere in the email title or the beginning of the body.我想知道是否有一种简单的方法可以在电子邮件标题或正文开头的某处包含导致错误的完整请求 url。

Currently I've to manually piece together the url from different request headers(domain, path and query) to know the incident site.目前,我必须手动将来自不同请求标头(域、路径和查询)的 url 拼凑在一起,以了解事件站点。

I'm aware of different global.asax hooks elmah provide, if something can be done in any of those events, I'd like to know from where I can grab an instance of the HttpContext or something to pull additional details from and add to the email body.我知道 elmah 提供了不同的 global.asax 钩子,如果可以在这些事件中的任何一个中完成某些操作,我想知道我可以从哪里获取HttpContext的实例或从中提取其他详细信息并添加到的内容电子邮件正文。 But if there is any existing built in configuration option to include this info, that would be a better bet I guess.但是,如果有任何现有的内置配置选项来包含此信息,我想这将是一个更好的选择。

Actually it was simple.其实很简单。 It was me ignoring the obvious.是我忽略了显而易见的事情。 Simply add this handler in the Global.asax and you are done.只需在Global.asax添加此处理程序即可完成。

protected void ErrorMail_Mailing(object sender, Elmah.ErrorMailEventArgs e)
{
   e.Mail.Body = Context.Request.Url.ToString()+ "\r\n" + e.Mail.Body;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM