HttpContext.Current在ELMAH的ErrorMail_Mailing处理程序(在Global.asax中)内返回null

时间:2013-02-07 12:38:10

标签: asp.net-mvc elmah httpcontext

我们正在ELMAH申请MVC asp.net 当任何exception发生时ELMAH发送错误邮件,其中包含事件ErrorMail_Mailing,
我在Global.asax中编写此事件的处理程序 并尝试从HttpContext.Current.Items变量读取值,但获取null exception
任何工作请帮助。

我正在应用斯科特的建议: - http://scottonwriting.net/sowblog/archive/2011/01/06/customizing-elmah-s-error-emails.aspx 在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;
            }
        }

1 个答案:

答案 0 :(得分:0)

在MVC中,它将取决于您在HttpContext.Current.Items值的设置位置,以确定它是否可在ErrorEmailEvent中使用。请参考之前的SO问题 - HttpContext.Items with ASP.NET MVC,以获取有关正确设置或使用creating your own ITempDataProvider之类的替代方法的一些指导。