SIGN UP MEMBER LOGIN:    
ARTICLE

Website Error Reporter in ASP.NET

Posted by Abhimanyu Kumar Vatsa Articles | ASP.NET Programming December 22, 2011
In this article and video post, you will learn how to develop such web application in ASP.NET which can report to the Admin guy about the errors that end users (website users) is experiencing on your blog/website. After reading this post you are definitely going to add this feature to your existing website or blog.
Reader Level:
Download Files:
 

Introduction

image002.jpg

I know I'm bit fogy in programming, but I write whatever I experience or learn. Within last 2-3 days I experienced errors on very-very popular websites namely Google, Yahoo and even few technical community websites. I can't doubt on Google or Yahoo because they have very highly qualified system to deal with.

image004.jpg

image006.jpg

But I can doubt on websites which redirect me on the page having following message:

image008.jpg

Displayed error page "Server Error in '/' Application.", means they are not dealing properly with errors. When I reported to the admin guys, they again asked me back to provide the source URL and target URL, where I saw this error. Even in past I was asking the same from my blog (www.itorian.com) users to provide the broken links or some other bugs. So, it is normal thing in web apps.

Developing bug free website is desired by every Web Technologist. We can't fix our 100% bugs from our applications especially from web platform, because on web platform we not only program code-behind, databases and views even managing each and every URL's on website is also big task.

Well, I experience this so, I'm going to write the same post which describes how to deal.

image010.jpg



Now, follow the steps (described in video) to create such Web application.


Step1

Create Web Application by navigating File > New > Project > ASP.NET Web Application.

Step2

Open the Global.asax file and type following coding in Application_Error.

void Application_Error(object sender, EventArgs e)

{

    // Code that runs when an unhandled error occurs

    Response.Write("<h2>Error Page</h2>");

       

    // Get the exception details

    Exception exc = Server.GetLastError();

    Response.Write("Sorry for the inconvenience that may have been caused to you.");

    Response.Write("<b>Error Message</b><p>" + exc.Message + "</p><br>");

       

    // Clear the error from the server

    Server.ClearError();

 

    // Report to Administrator

    string url = HttpContext.Current.Request.Url.AbsoluteUri;

    string MailBody = "Website user is getting bad experience on you website. Find the details below:<br><br>";

    MailBody = MailBody + "<br><br><b>Error on Page (Target Webpage): </b>" + url;

    MailBody = MailBody + "<br><br><b>Link on Webpage (Source Webpage): </b>" + Request.UrlReferrer;

    MailBody = MailBody + "<br><br><b>Error Message: </b>" + exc.Message;

    MailBody = MailBody + "<br><br><b>Trace Message: </b>" + exc.StackTrace;

       

    // Other browser based stuffs

    MailBody = MailBody + "<br><br><b>Platform: </b>" + Request.Browser.Platform;

    MailBody = MailBody + "<br><br><b>Browser: </b>" + Request.Browser.Browser;

    MailBody = MailBody + "<br><br><b>Browser Type: </b>" + Request.Browser.Type;

    MailBody = MailBody + "<br><br><b>Browser Version: </b>" + Request.Browser.Version;

       

    string MailResponse = sendmail("abhikumarvatsa@yahoo.co.in", "Bad Experience", MailBody);

    Response.Write("<br><br><b>Note: </b>" + MailResponse.ToString());

}

 

Step3

Create a new method in Global.asax file for sendmail method as given in above code. Here is the method code:

private string sendmail(string ToEmailAdd, string MailSubject, string MailMessageHTMLString)

{

    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

 

    message.To.Add(new System.Net.Mail.MailAddress(ToEmailAdd));

    message.From = new System.Net.Mail.MailAddress("abhimanyukumarvatsa@itorian.com", "ITORIAN.COM");

    message.Subject = MailSubject;

    message.Body = MailMessageHTMLString;

    message.IsBodyHtml = true;

 

    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();

 

    client.Port = 25;

    client.Host = "mail.itorian.com";

    System.Net.NetworkCredential nc = new System.Net.NetworkCredential("abhimanyukumarvatsa@itorian.com", "*****");

    client.UseDefaultCredentials = false;

    client.Credentials = nc;

 

    try

    {

        client.Send(message);

        return "Automated System success to report this to the Administrator.";

    }

    catch

    {

        return "Automated System not success to report this to the Administrator.";

    }

}

 

Step4

Now open the Site.Master and create any broken link or any other runtime mistake and then run the project.

Step5

Type to navigate by clicking broken link, it will display the error message instead of displaying the red page error and also sends the email to you inbox containing full error description in body.


Video Post of this article

Untitled.jpg

Login to add your contents and source code to this article
share this article :
post comment
 

thank's for sharing good efforts!

Posted by Andrew Finlander Dec 22, 2011

This article is very helpful ,thanks for sharing

Posted by Nitin Singh Dec 22, 2011

You have provided us a great insight of the the error reporter..thanks

Posted by Akash Ahlawat Dec 22, 2011

Very helpful article. Thanks, for sharing.

Posted by Alok Pandey Dec 22, 2011

Definitely, great feature Abhimanyu I going to add this feature now.....

Posted by Manish Tewatia Dec 22, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor