Click here to Skip to main content
12,448,720 members (52,905 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.9K views
3 bookmarked
Posted

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
Project Lead
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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralReason for my vote of 5 Even better... thanks for expanding ... Pin
BrianBissell20-Oct-11 8:27
memberBrianBissell20-Oct-11 8:27 
GeneralThis is very nice way to get error report from the website.W... Pin
Mike Thom12-Oct-11 19:13
memberMike Thom12-Oct-11 19:13 
GeneralRe: Thanks Mike Pin
Mukund Thakker17-Oct-11 18:55
memberMukund Thakker17-Oct-11 18:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.160811.3 | Last Updated 13 Oct 2011
Article Copyright 2011 by Mukund Thakker
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid