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

x
?
Solved

IIS 7 404 Error Overrides Global Application_Error Handler

Posted on 2011-02-22
7
Medium Priority
?
2,142 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:mgabr123
[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
  • 3
  • 2
7 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34956073
Check for the properties of this section of your web.config:

            
<!--Upgraded by Core Upgrade version 5.5.1 - Date: 12/15/2010 10:13:51 AM-->
		<!--<customErrors mode="RemoteOnly" redirectMode="ResponseRewrite" defaultRedirect="~/errorpage.aspx" />-->
		<customErrors mode="RemoteOnly" redirectMode="ResponseRewrite" defaultRedirect="~/errorpage.aspx"/>

Open in new window

0
 

Author Comment

by:mgabr123
ID: 34956284
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
0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34956806
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)

<customErrors mode="RemoteOnly" defaultRedirect="/error.html"> 
       <error statusCode="403" redirect="/accessdenied.html" /> 
       <error statusCode="404" redirect="/pagenotfound.html" /> 
   </customErrors>

Open in new window


Here is a VB oriented but excellent and extremely thorough tutorial: http://www.15seconds.com/issue/030102.htm
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:mgabr123
ID: 34960877
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


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();
    }

Open in new window

0
 

Accepted Solution

by:
mgabr123 earned 0 total points
ID: 34960982
I was able to locate the explaination as to why my the error handling wasn't firing at the end of the attached MSDN artical:

http://msdn.microsoft.com/en-us/library/24395wz3.aspx

"An error handler that is defined in the Global.asax file will only catch errors that occur during processing of requests by the ASP.NET runtime. For example, it will catch the error if a user requests an .aspx file that does not occur in your application. However, it does not catch the error if a user requests a nonexistent .htm file. For non-ASP.NET errors, you can create a custom handler in Internet Information Services (IIS). The custom handler will also not be called for server-level errors."

0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35913547
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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