I have created a custom http module. In this class I've got an Init method that initializes the OnError event handler. It all works fine when I run the website from with the Visual Studio environment, that is when an error is raised, the OnError method of
the module get fired and it shows me a page I've created to show some sort of information about the error.
However, the problem is that when I deploy the site, the error is shown as a .Net error and not on the custom error page, it seems that the module is not known as the OnError methos does not fire.
I have added stuff to my web.config file.
I also have manualy added a managed module to the IIS and config settings to the web.config in the System.WebServer section.
Afterall, it doesn't work.
Can anyone tell me what I'm missing in configuration or anything else that prevnets the module to work on the deployed website?!
Instead of using custom HTTP modules, why not just use the <customErrors> section of web.config? You can redirect the user to a page of your choosing when any unhandled exception is thrown, then on that page, you can use Server.GetLastError() and Server.ClearError()
to find out what the error was and display some information to the user.
It is a lot easier than using custom http modules for error handling (:
If anyone is using an httpmodule for error handling, note that you need to clear the error before actually make use of the it (in my case redircting to an error page and displaying the error message).
leila
Member
76 Points
183 Posts
Custom HttpModule
Jan 27, 2009 11:16 AM|LINK
Hi everyone,
I have created a custom http module. In this class I've got an Init method that initializes the OnError event handler. It all works fine when I run the website from with the Visual Studio environment, that is when an error is raised, the OnError method of the module get fired and it shows me a page I've created to show some sort of information about the error.
However, the problem is that when I deploy the site, the error is shown as a .Net error and not on the custom error page, it seems that the module is not known as the OnError methos does not fire.
I have added stuff to my web.config file.
I also have manualy added a managed module to the IIS and config settings to the web.config in the System.WebServer section.
Afterall, it doesn't work.
Can anyone tell me what I'm missing in configuration or anything else that prevnets the module to work on the deployed website?!
Thanks in advance for your help.
bgs264
Participant
1083 Points
211 Posts
Re: Custom HttpModule
Jan 27, 2009 12:38 PM|LINK
Instead of using custom HTTP modules, why not just use the <customErrors> section of web.config? You can redirect the user to a page of your choosing when any unhandled exception is thrown, then on that page, you can use Server.GetLastError() and Server.ClearError() to find out what the error was and display some information to the user.
It is a lot easier than using custom http modules for error handling (:
leila
Member
76 Points
183 Posts
Re: Custom HttpModule
Jan 27, 2009 01:00 PM|LINK
well, to be honest I've tried that butfor some reason the server.GetLastError is always null even though an error is raised.
anyway, I came across an article about using http modules for error handling and I'm really intrested to make it work.
but thanks for your suggestion.
leila
Member
76 Points
183 Posts
Re: Custom HttpModule
Feb 03, 2009 04:10 PM|LINK
GOT IT!!!!
If anyone is using an httpmodule for error handling, note that you need to clear the error before actually make use of the it (in my case redircting to an error page and displaying the error message).