Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help implementing an error handling utility on web applicaiton

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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