3

We are using ELMAH for our MVC asp.net application.
When any exception occurs ELMAH sends error mail which has an event ErrorMail_Mailing,
I am writing handler for this event inside my Global.asax
and trying to read value from HttpContext.Current.Items variable but getting null exception.

Any work around please help.

I am applying what Scott is suggesting here:- http://scottonwriting.net/sowblog/archive/2011/01/06/customizing-elmah-s-error-emails.aspx In global.asax.cs I am trying to write below event handler, where I want to configure subject line of error mail with something stored inside my 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;
            }
        }
tereško
  • 58,060
  • 25
  • 98
  • 150
  • welcome to SO. :) you are trying to write handler inside Gloabal.asax? Please put some code. – शेखर Feb 07 '13 at 12:44
  • I am trying to achieve same thing mentioned in the below blog :- http://scottonwriting.net/sowblog/archive/2011/01/06/customizing-elmah-s-error-emails.aspx?CommentPosted=true#commentmessage Thanks, I am updating my question also. – Vilakshan Dubey Feb 07 '13 at 13:23

1 Answers1

0

Within MVC it will depend on where you are setting the HttpContext.Current.Items value as to whether it will be available in the ErrorEmailEvent. Please reference the previous SO question - HttpContext.Items with ASP.NET MVC for some guidance on setting this properly or an using alternate means like creating your own ITempDataProvider.

Community
  • 1
  • 1
Paige Cook
  • 22,415
  • 3
  • 57
  • 68