Click here to Skip to main content
11,933,905 members (45,570 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked

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();
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%}", 
    result = result.Replace("{%ReferrerUrl%}", "None");

An Error occurred on {%Website%} at {%Time%}. 
Page URL: {%ErrorUrl%} 
Referral URL:{%ReferrerUrl%} 
Browser Type: {%Browser%} 
Client IP Address: {%ClientIP%} 
UserName: {%username%} 
Error Detail: 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mukund Thakker
Technical Lead
India India
Tech Lead
MCTS - .NET Framework 4.0, Web Applications

Blog :

Don't code today, what you can't debug tomorrow!
Everything makes sense in someone's mind

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 Even better... thanks for expanding ... Pin
BrianBissell20-Oct-11 9:27
memberBrianBissell20-Oct-11 9:27 
GeneralThis is very nice way to get error report from the website.W... Pin
Mike Thom12-Oct-11 20:13
memberMike Thom12-Oct-11 20:13 
GeneralRe: Thanks Mike Pin
Mukund Thakker17-Oct-11 19:55
memberMukund Thakker17-Oct-11 19: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
Web04 | 2.8.151126.1 | Last Updated 13 Oct 2011
Article Copyright 2011 by Mukund Thakker
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid