Click here to Skip to main content
13,005,192 members (63,639 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 12 Oct 2011

Send ASP.NET formatted exception details via email

, 12 Oct 2011
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
Project 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 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.

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