Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Send ASP.NET formatted exception details via email

0.00/5 (No votes)
12 Oct 2011 1  
We can include some more information like browser, client's IP address etc.string result = ;System.IO.StreamReader objReader = default(System.IO.StreamReader);objReader = new System.IO.StreamReader(error.htm);result = objReader.ReadToEnd();objReader.Close();result =...

We can include some more information like browser, client's IP address etc.


C#
string result = "";
System.IO.StreamReader objReader = default(System.IO.StreamReader);
objReader = new System.IO.StreamReader("error.htm");

result = objReader.ReadToEnd();
objReader.Close();
result = result.Replace("{%Time%}", DateTime.Now.ToLocalTime().ToString());
result = result.Replace("{%ErrorUrl%}", Request.Url.AbsoluteUri.ToString());
result = result.Replace("{%Browser%}", Request.Browser.Type.ToString() + 
         "<br/>" + Request.Browser.Browser.ToString());
result = result.Replace("{%ClientIP%}", Request.UserHostAddress.ToString());

result = result.Replace("{%ErrorDetail%}", Context.Server.GetLastError().ToString());

if (Request.UrlReferrer != null)
{
    result = result.Replace("{%ReferrerUrl%}", 
             Request.UrlReferrer.AbsoluteUri.ToString());
}
else
{
    result = result.Replace("{%ReferrerUrl%}", "None");
}


/*******************************************************
error.htm
Hello,

An Error occurred on {%Website%} at {%Time%}. 

Page URL: {%ErrorUrl%} 

Referral URL:{%ReferrerUrl%} 

Browser Type: {%Browser%} 

Client IP Address: {%ClientIP%} 

UserName: {%username%} 

Error Detail: 

{%ErrorDetail%} 

*******************************************************/

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here