mgabr123
asked on
IIS 7 404 Error Overrides Global Application_Error Handler
I am having a bit of trouble with Custom Error handling through the Global.aspx event handler Application_Error and IIS 7. The 404 custom error handling works fine in the following situation.
http://www.mysite.com/test.aspx
However, both of the following would bypass the Application_Error handler in Global.aspx and
invoke the IIS error handler:
http://www.mysite.com/test
http://www.mysite.com/test.test
Any help would be appreciated,
TIA
http://www.mysite.com/test.aspx
However, both of the following would bypass the Application_Error handler in Global.aspx and
invoke the IIS error handler:
http://www.mysite.com/test
http://www.mysite.com/test.test
Any help would be appreciated,
TIA
ASKER
Hi rawinnlnx9,
I currently only have the following my webconfig:
<customErrors mode="On"></customErrors>
Should there be more to that section in order to ensure that the Applicaiton_Error handler in Global.aspx is called?
The handler seems to work perfectly when I test it under the Visual Studio test server but it doesn't work on the production IIS 7 server.
TIA
I currently only have the following my webconfig:
<customErrors mode="On"></customErrors>
Should there be more to that section in order to ensure that the Applicaiton_Error handler in Global.aspx is called?
The handler seems to work perfectly when I test it under the Visual Studio test server but it doesn't work on the production IIS 7 server.
TIA
Yes, this is why I encouraged you to investigate those fields and their arguments. Here let me help you get going so you can get past this:
http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
The above is an exact discussion from Microsoft on the subject.
See here below on how you address specific error numbers: (the example shows you how to handle 403, and 404 errors)
Here is a VB oriented but excellent and extremely thorough tutorial: http://www.15seconds.com/issue/030102.htm
http://msdn.microsoft.com/en-us/library/h0hfz6fc.aspx
The above is an exact discussion from Microsoft on the subject.
See here below on how you address specific error numbers: (the example shows you how to handle 403, and 404 errors)
<customErrors mode="RemoteOnly" defaultRedirect="/error.html">
<error statusCode="403" redirect="/accessdenied.html" />
<error statusCode="404" redirect="/pagenotfound.html" />
</customErrors>
Here is a VB oriented but excellent and extremely thorough tutorial: http://www.15seconds.com/issue/030102.htm
ASKER
Hi Rawinlnx9,
I looked through that code but I don't see how anything in the webconfig.ini would keep the Applicaiton_Error handler from firing in the Global.aspx file. According to the articals you linked to the error handling order is as follows:
1 .On the Page itself, in the Page_Error
2. The global.asax Application_Error
3. The web.config file
I have the following code in my Global.aspx file which actually does all my error handling and emails it to my support staff. My problem is that Application_Error does not fire on my IIS server for some reason that I have not been able to determine. If my understanding is correct the call to Server.ClearError() at this level shouldn't even let the error reach the webconfig.ini.
Thanks
I looked through that code but I don't see how anything in the webconfig.ini would keep the Applicaiton_Error handler from firing in the Global.aspx file. According to the articals you linked to the error handling order is as follows:
1 .On the Page itself, in the Page_Error
2. The global.asax Application_Error
3. The web.config file
I have the following code in my Global.aspx file which actually does all my error handling and emails it to my support staff. My problem is that Application_Error does not fire on my IIS server for some reason that I have not been able to determine. If my understanding is correct the call to Server.ClearError() at this level shouldn't even let the error reach the webconfig.ini.
Thanks
void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString();
SendMail SendMail = new SendMail();
SendMail.BySystem("email@email.com", "Error in Application", err);
Exception ex = Server.GetLastError();
if (ex is HttpException || ((HttpException)(ex)).GetHttpCode() == 404)
{
Server.Transfer("~/404Error.aspx");
}
else
{
Server.Transfer("~/ServerError.aspx");
}
Server.ClearError();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Open in new window