我们在MVC asp.net应用程序中使用ELMAH。
当发生任何exception时,ELMAH发送具有事件ErrorMail_Mailing的错误消息,
我正在Global.asax中编写此事件的处理程序
尝试从HttpContext.Current.Items变量中读取值,但得到null exception。
任何工作都请提供帮助。
我在这里应用了斯科特的建议:-在global.asax.cs中,我正在尝试编写下面的事件处理程序,其中我希望使用存储在HttpContext.Current.Items中的内容来配置错误邮件的主题行
protected void ErrorMail_Mailing(object sender, Elmah.ErrorMailEventArgs e)
{
if (HttpContext.Current.Items["CustomerName"] != null)
{
e.Mail.Subject = "Error came to / " + HttpContext.Current.Items["CustomerName"] + " / Error Type: " +
e.Error.Type;
}
}发布于 2013-02-08 10:26:42
在MVC中,这将取决于您设置HttpContext.Current.Items值的位置,以及它是否会在ErrorEmailEvent中可用。请参考前面的SO问题- HttpContext.Items with ASP.NET MVC,以获得有关正确设置或使用creating your own ITempDataProvider等替代方法的一些指导。
https://stackoverflow.com/questions/14751326
复制相似问题