Solved

Help implementing an error handling utility on web applicaiton

Posted on 2006-11-02
6
218 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now