Contents
Introduction
The code below is included in your Global.asax file. It will send a message to the specified email address when there is an error in your application. We have included more that just the error message. Merely remove any lines that you don't want included. You should also include System.Text for the StringBuilder function and System.Mail for the email functions.
Top 
Warning
If you have lots of untrapped errors possibilities, you will get lots of messages. But, it will keep you informed - one of our sites that I administer remotely had a full transaction logfile. When an individual attempted to log into the site, an error message was generated and we were able to correct the problem with 5 minutes.
public void Application_Error(object sender, EventArgs e)
{
// Get the last Server Error
Exception myError =HttpContext.Current.Server.GetLastError();
StringBuilder Sb = new StringBuilder();
Sb.Append("[HTML][HEAD][TITLE]Error Message[/TITLE][/HEAD][BODY][P]");
Sb.Append("[br][br]Error Message");
Sb.Append("[br][i]Remote IP: [/i]"+HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
Sb.Append("[br][i]Host: [/i]"+HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]);
Sb.Append("[br][i]Platform: [/i]"+HttpContext.Current.Request.Browser.Platform);
Sb.Append("[br][i]Browser: [/i]"+HttpContext.Current.Request.Browser.Browser);
Sb.Append("[br][i]Type: [/i]"+HttpContext.Current.Request.Browser.Type);
Sb.Append("[br][i]Version: [/i]"+HttpContext.Current.Request.Browser.Version);
Sb.Append("[br][i]Cookies: [/i]"+HttpContext.Current.Request.Browser.Cookies.ToString());
Sb.Append("[br][i]Path: [/i]"+HttpContext.Current.Request.Path);
Sb.Append("[br][i]Full Path: [/i]"+HttpContext.Current.Request.RawUrl);
Sb.Append("[br]");
Sb.Append("[br][i]Error Msg: [/i]"+myError.Message);
Sb.Append("[br]");
Sb.Append("[br][i]Error Src: [/i]"+myError.Source);
Sb.Append("[br]");
Sb.Append("[br][i]Stack: [/i]"+myError.StackTrace);
Sb.Append("[br]");
Sb.Append("[br][i]Target: [/i]"+myError.TargetSite);
Sb.Append("[/BODY][/HTML]");
// Send the Message
MailMessage msgMail = new MailMessage();
msgMail.To = "your@emailaddress.com";
msgMail.From = "your@emailaddress.com";
msgMail.Subject = "Auto Generated Error Message";
msgMail.BodyFormat = MailFormat.Html;
msgMail.Body = Sb.ToString();
SmtpMail.Send(msgMail);
}
Top 