Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Send ASP.NET formatted exception details via email

, 12 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mukund Thakker
Technical Lead
India India
Software Developer
MCTS - .NET Framework 4.0, Web Applications
 
Blog : http://thakkermukund.wordpress.com
Twitter@thakkermukund
 
Don't code today, what you can't debug tomorrow!
Everything makes sense in someone's mind
Follow on   Twitter

Comments and Discussions

 
GeneralReason for my vote of 5 Even better... thanks for expanding ... PinmemberBrianBissell20-Oct-11 9:27 
GeneralThis is very nice way to get error report from the website.W... PinmemberMike Thom12-Oct-11 20:13 
GeneralRe: Thanks Mike PinmemberMukund Thakker17-Oct-11 19:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 13 Oct 2011
Article Copyright 2011 by Mukund Thakker
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid