I managed to secure all applications on my server with the custom errors script section mentioned in Scott Gu's blog post. All but one website...
That particular website redirects errors for all error codes to the same page, except 404 errors. For 404 errors it shows a standard 404 error page that seems to come with IIS 7.
If I read it correctly then that should also redirect to the same error page that you are using in the <customErrors> section. Then your config file should look like this:
Changing or removing the httpErrors section seems to alter the error page. But now I just get a different GENERIC error page and still not the page I actually need to display.
For testing purposes I have replaced the httpErrors section with this:
There is no redirection though. Just a generic error page saying "The page cannot be displayed because an internal server error has occurred.". I made sure that /Error/ServerError works fine, so I don't think this could be the problem.
Is that app by any chance set up for the 1.1 framework?
If so you may be seeing an error with the TryCast code in the error page.
If you have access to log on to that server, Try setting your error mode to LocalOnly and then log on to the server and request a non existent page. Instead of a generic page, you should get the real error page so you can see what's wrong.
There's nothing to see with LocalErrors. My problem is that I get a generic 404 page, not an internal server error (or the custom error page that should actually appear).
Agreed. I had the same issue. In VS if you do Ctrl-Alt-E and enable breaking on the managed code first chance exceptions you can see where you code is possibly using a resource not available during a 404.
James52
0 Points
6 Posts
Custom errors section does not redirect 404 errors
Sep 18, 2010 02:09 PM|LINK
Hi,
I managed to secure all applications on my server with the custom errors script section mentioned in Scott Gu's blog post. All but one website...
That particular website redirects errors for all error codes to the same page, except 404 errors. For 404 errors it shows a standard 404 error page that seems to come with IIS 7.
The custom errors section looks like this:
Other sites on the same server do not have this problem. Please advise.
KalleH
Member
4 Points
5 Posts
Re: Custom errors section does not redirect 404 errors
Sep 18, 2010 02:56 PM|LINK
Hi
IIS 7 has it's own error handling apart from .NET's error handling. The configuration for that is located under
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><httpErrors defaultResponseMode="ExecuteURL" defaultPath="~/error.aspx"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <clear/></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <error statusCode="404" responseMode="ExecuteURL" path="/Page-not-found/"/></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </httpEr</div>If I read it correctly then that should also redirect to the same error page that you are using in the <customErrors> section. Then your config file should look like this:
By adding the <clear/> tag you override all default configuration and your error page should redirect correctly.
Please correct me if I'm wrong
James52
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 07:49 AM|LINK
Changing or removing the httpErrors section seems to alter the error page. But now I just get a different GENERIC error page and still not the page I actually need to display.
For testing purposes I have replaced the httpErrors section with this:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <httpErrors errorMode="Custom" defaultResponseMode="Redirect" defaultPath="~/Error/ServerError"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <clear/></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </httpErrors></div><httpErrors errorMode="Custom" defaultResponseMode="Redirect" defaultPath="~/Error/ServerError">
<clear/>
</httpErrors>
There is no redirection though. Just a generic error page saying "The page cannot be displayed because an internal server error has occurred.". I made sure that /Error/ServerError works fine, so I don't think this could be the problem.
Please help!
mbanavige
All-Star
134962 Points
15421 Posts
ASPInsiders
Moderator
MVP
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 12:01 PM|LINK
Is that app by any chance set up for the 1.1 framework?
If so you may be seeing an error with the TryCast code in the error page.
If you have access to log on to that server, Try setting your error mode to LocalOnly and then log on to the server and request a non existent page. Instead of a generic page, you should get the real error page so you can see what's wrong.
James52
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 02:19 PM|LINK
Hi Mike,
The site is running .NET 4.0
There's nothing to see with LocalErrors. My problem is that I get a generic 404 page, not an internal server error (or the custom error page that should actually appear).
jamescd
Member
2 Points
4 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 10:18 AM|LINK
Is your AppPool in Classic mode? If so, then the script map will not utilize the ASP.NET for non-.NET file types?
James52
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 07:17 PM|LINK
No, the App Pool is running in Integrated mode.
Still haven't found any way around this... please help!
Rovastar
Member
182 Points
59 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 07:28 PM|LINK
I think you will need to go to an actual page rather than a path
<customErrors mode="On" defaultRedirect="/Error/ServerError/500" />
<httpErrors errorMode="Custom" defaultResponseMode="Redirect" defaultPath="~/Error/ServerError">
You have been trying to go to somewhere with and extension. Try something like:
<customErrors mode="On" defaultRedirect="/Error/ServerError/500.aspx" />
If not try going to a basic htm page first and then to aspx pages.
mbanavige
All-Star
134962 Points
15421 Posts
ASPInsiders
Moderator
MVP
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 11:12 PM|LINK
Do you have something in your error page page that is accessing Session?
Or is your error page using a masterpage or other control that might access Session?
While testing,
As soon as i removed any Session access, my custom error page appeared.
sideout
Member
220 Points
68 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 11:32 PM|LINK
Agreed. I had the same issue. In VS if you do Ctrl-Alt-E and enable breaking on the managed code first chance exceptions you can see where you code is possibly using a resource not available during a 404.