Problem with web application exception handling

Last post 09-09-2005 1:18 PM by new2aspdotnet. 1 replies.

Sort Posts:

  • Problem with web application exception handling

    09-08-2005, 12:26 PM
    • Participant
      1,179 point Participant
    • new2aspdotnet
    • Member since 08-12-2004, 12:07 PM
    • Posts 345
    Hi,

    I implemented a httpmodule to handle exceptions. But when I tested it in a web application, the httpmodule code does not seem to execute. I dont have VS.Net to set breakpoints and debug. So I commented all but four lines in the httpmodule which just writes out the exception message. This is what I have in the httpmodule.

                        public void Init(System.Web.HttpApplication Application)
                       {
                             Application.Error += new EventHandler(OnError);
                        }

                        public void Dispose()
                       {
                        }

                        protected virtual void OnError(object sender, EventArgs args)
                       {
                           HttpApplication app = ((HttpApplication)(sender));
                           HttpContext.Current.Response.Write(app.Server.GetLastError().Message);
                           HttpContext.Current.Response.Flush();
                           HttpContext.Current.Server.ClearError();
                           HttpContext.Current.Response.End();
                        }

    I added a reference to this dll in my web application and changed the web.config to include this,

                      <httpModules>
                           <add name="handleexceptions" type="httpmoduleapp.handleexceptions, httpmoduleapp" />
                      </httpModules>

    But still when I test a page that throws an exception, I dont see the exception.message that I am writing out in the httpmodule. Instead the page is redirected to the default error page that is set in the web.config file even though I clear the error in the httpmodule. It looks like the httpmodule is not hooked up properly. Can any one tell me what am I missing here.

    Thanks.
  • Re: Problem with web application exception handling

    09-09-2005, 1:18 PM
    • Participant
      1,179 point Participant
    • new2aspdotnet
    • Member since 08-12-2004, 12:07 PM
    • Posts 345

    Ok got it workign.

Page 1 of 1 (2 items)