IIS 404 Custom Error not working as expected

When I tried to access fake .aspx page to make sure IIS returns custom 404 error page, I saw .net specific error “The resource cannot be found”.

Screenshot# 1

I was wondering why IIS custom 404 error page not being returned. I looked at that website’s web.config file and saw that customErrors section was not specified.  But it’s OK.  Gatekeeper(IIS) is there so it should return custom 404 error page.

hmmm…. OK finally found it.  There is an option called “Verify that file exists” in IIS6 (“Check that file exists” option in IIS 5.1) for .aspx page handler (aspnet_isapi.dll).  Here is where you can find it in IIS.

Screenshot# 2

  • If “Verify that file exists” option is  unchecked, .ASPX page handler(aspnet_isapi.dll) looks for the fake .aspx page and if it doesn’t find it, it returns its own “Resource cannot be found” error because there is no customErrors section setup in web.config file.
  • If “Verify that file exists” option is checked, IIS makes sure that .aspx page exists or not.  IIS returns custom 404 error page setup in IIS if .aspx page doesn’t exists. If IIS finds requested .aspx page, it forwards request to aspnet_isapi to handle that request.

Note: If IIS doesn’t find the file specified for custom error code, it will send generic error message “The system cannot find the file specified”.

Conclusion:

If you don’t have customErrors section setup in web.config,  you need to check “Verify that file exists” option to true for .aspx page handler in IIS to handle 404ed .

Posted in Microsoft Technology Tagged with: ,
One comment on “IIS 404 Custom Error not working as expected
  1. Steve says:

    Dude…thanks!!

Ads