Solved

Help implementing an error handling utility on web applicaiton

Posted on 2006-11-02
6
224 Views
Last Modified: 2012-06-27
Visual Studio 2003 with .NET 1.1.  (no 2.0 as of yet)

So far my experience with error reporting when working on a web application has been rather weak and recently I ran into this article
http://www.codeproject.com/aspnet/GlobalErrorHandler.asp
that sounds somewhat promising if it can be implemented quickly.  I am somewhat of a beginner so please do not assume much or at least explain with clear and thorough intructions.

What I understand is that the errorhandler function here can be compiled as its own standalone class and be incorporated into any web application project.  Could you please explain from beginning to end how to create this class and incorporate it into a web application?  The download file is unavailable and it seems that the article is missing a few steps if you were to create the class from scratch.  If you have a better suggestion for doing something similar please make it although I like the idea of having a web error reporting utility/class that I can add to webapp projects while in development.  

Thank you very much in advance.
0
Comment
Question by:wsbdc-questions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17858596
Here is the source, it downloads fin for me :

using System;
using System.Web;
using System.Collections.Specialized;
using System.Reflection;
using System.Diagnostics;

namespace MyApps.Utilities
{
      public class GlobalErrorHandler : IHttpModule
      {
            public void Init (HttpApplication app)
            {
                  app.Error += new System.EventHandler (OnError);
            }

            public void OnError (object obj, EventArgs args)
            {
                  // At this point we have information about the error
                  HttpContext ctx = HttpContext.Current;
                  HttpResponse response = ctx.Response;
                  HttpRequest request = ctx.Request;

                  Exception exception = ctx.Server.GetLastError();

                  response.Write("Your request could not processed. Please press the back button on your browser and try again.<br/>");
                  response.Write("If the problem persists, please contact technical support<p/>");
                  response.Write("Information below is for technical support:<p/>");
                  
                  string errorInfo = "<p/>URL: " + ctx.Request.Url.ToString () + "<p/>Stacktrace:---<br/>" + exception.InnerException.StackTrace.ToString() + "<p/>Error Message:<br/>" + exception.InnerException.Message;

                  response.Write("Querystring:<p/>");

                  for(int i=0;i<request.QueryString.Count;i++)
                  {
                        response.Write("<br/>" + request.QueryString.Keys[i].ToString() + " :--" + request.QueryString[i].ToString() + "--<br/>");// + nvc.
                  }

                  response.Write("<p>-------------------------<p/>Form:<p/>");

                  for(int i=0;i<request.Form.Count;i++)
                  {
                        response.Write("<br/>" + request.Form.Keys[i].ToString() + " :--" + request.Form[i].ToString() + "--<br/>");// + nvc.
                  }

                  response.Write("<p>-------------------------<p/>ErrorInfo:<p/>");

                  response.Write (errorInfo);

                  // --------------------------------------------------
                  // To let the page finish running we clear the error
                  // --------------------------------------------------
                  ctx.Server.ClearError ();
            }

            public void Dispose () {}
      }
}
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17858614
You start a new C# project in Visual Studio of Type class library.
Paste the code above into it.
You will need to fix the namespaces etc.

Compile.
Put in the bin folder of the web app.
Modify the web.config as described.

Should work OK.

Can email you the source zip file if required.
0
 

Author Comment

by:wsbdc-questions
ID: 17859491
Thank you, that worked.  Now, could you provide an example of using the error handler?  I believe this handler works as a result of an application error.  Is there a way, perhaps by throwing an error, to put this class to use not only for error reporting but also for simple debugging?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 15

Expert Comment

by:ozymandias
ID: 17860761
Do you want a separator on a menu or a separator on a toolbar ?

The items go on the Menu in the order you add them the same with the toolbar.

If you want a separator on a toolbar add a button and set its style to separator.
If you want a separator on a menu add a menuitem and set its text to "-".

If you want to add either in a particlar place use the Insert() method instead of the Add() method and specify the index at which the item is to be inserted.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17861653
sorry, that last comment went in the wrong question.
0
 

Author Comment

by:wsbdc-questions
ID: 17901397
No problem.  I actually like this class a lot.  Is there a way to use it not only for error reporting but also for debugging?

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question