Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help implementing an error handling utility on web applicaiton

Posted on 2006-11-02
6
Medium Priority
?
226 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 1500 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
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!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

824 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