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.
Here is the problem: The code worked fine on my Windows 7 developer machine’s localhost, but when I copied the code to my Windows 2008 server, the IIS refused to call my custom page, displaying the default
404 error page instead.
Here is the catch: The Windows 2008 server is running the latest IIS 7.5, and this version will
by default “override” the HTTP response with its default error pages if the page returns a HTTP error status code (like 404, or 500).
Here is the solution: .NET 3.5 has a new property calledResponse.TrySkipIisCustomErrors that will, if set to true,
instruct IIS 7.5 to ignore it’s own default error pages, allowing me to use my own. The code change is very small, but highly effective:
Here is the problem: The code worked fine on my Windows 7 developer machine’s localhost, but when I copied the code to my Windows 2008 server, the IIS refused to call my custom page, displaying the default
404 error page instead.
Here is the catch: The Windows 2008 server is running the latest IIS 7.5, and this version will
by default “override” the HTTP response with its default error pages if the page returns a HTTP error status code (like 404, or 500).
Here is the solution: .NET 3.5 has a new property calledResponse.TrySkipIisCustomErrors that will, if set to true,
instruct IIS 7.5 to ignore it’s own default error pages, allowing me to use my own. The code change is very small, but highly effective:
None
0 Points
6 Posts
Custom errors section does not redirect 404 errors
Sep 18, 2010 10:09 AM|James52|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.
None
0 Points
5 Posts
Re: Custom errors section does not redirect 404 errors
Sep 18, 2010 10:56 AM|KalleH|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
None
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 03:49 AM|James52|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!
All-Star
160051 Points
13198 Posts
ASPInsiders
Moderator
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 08:01 AM|mbanavige|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.
None
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 19, 2010 10:19 AM|James52|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).
None
0 Points
4 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 06:18 AM|jamescd|LINK
Is your AppPool in Classic mode? If so, then the script map will not utilize the ASP.NET for non-.NET file types?
None
0 Points
6 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 03:17 PM|James52|LINK
No, the App Pool is running in Integrated mode.
Still haven't found any way around this... please help!
Member
120 Points
83 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 03:28 PM|Rovastar|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.
All-Star
160051 Points
13198 Posts
ASPInsiders
Moderator
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 07:12 PM|mbanavige|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.
Member
1 Points
60 Posts
Re: Custom errors section does not redirect 404 errors
Sep 20, 2010 07:32 PM|sideout|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.
None
0 Points
2 Posts
Re: Custom errors section does not redirect 404 errors
Oct 11, 2012 03:35 AM|ranijhani|LINK
Hi James,
Even I had the same Issue, But i found solution in the below page : http://briancaos.wordpress.com/2012/06/12/custom-404-page-ignored-by-iis-7/
If your IIS does not display your own custom error page, this might be the problem – and the solution:
I recently had to implement a custom 404 error page. The code for that is pretty simple. In the web.config, the custom 404 error page is added:
<div id="highlighter_30866" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
<customErrors mode=
"Off"
>
2
<error statusCode=
"404"
redirect=
"/components/Error/404.aspx"
/>
3
</customErrors>
And the page is requested to return a 404 not found:
<div id="highlighter_959048" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
protected
void
Page_Load(
object
sender, EventArgs e)
2
{
3
Response.StatusCode = 404;
4
Response.StatusDescription =
"Page not found"
;
5
Response.Flush();
6
}
Here is the problem: The code worked fine on my Windows 7 developer machine’s localhost, but when I copied the code to my Windows 2008 server, the IIS refused to call my custom page, displaying the default 404 error page instead.
Here is the catch: The Windows 2008 server is running the latest IIS 7.5, and this version will by default “override” the HTTP response with its default error pages if the page returns a HTTP error status code (like 404, or 500).
Here is the solution: .NET 3.5 has a new property calledResponse.TrySkipIisCustomErrors that will, if set to true, instruct IIS 7.5 to ignore it’s own default error pages, allowing me to use my own. The code change is very small, but highly effective:
<div id="highlighter_895425" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
protected
void
Page_Load(
object
sender, EventArgs e)
2
{
3
// Allow me to use my own error page:
4
Response.TrySkipIisCustomErrors =
true
;
5
Response.StatusCode = 404;
6
Response.StatusDescription =
"Page not found"
;
7
Response.Flush();
8
}
None
0 Points
2 Posts
Re: Custom errors section does not redirect 404 errors
Oct 11, 2012 03:37 AM|ranijhani|LINK
Hi James,
Even i had the same Issue Found Solution in the below Link Please check :
http://briancaos.wordpress.com/2012/06/12/custom-404-page-ignored-by-iis-7/
If your IIS does not display your own custom error page, this might be the problem – and the solution:
I recently had to implement a custom 404 error page. The code for that is pretty simple. In the web.config, the custom 404 error page is added:
<div id="highlighter_30866" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
<customErrors mode=
"Off"
>
2
<error statusCode=
"404"
redirect=
"/components/Error/404.aspx"
/>
3
</customErrors>
And the page is requested to return a 404 not found:
<div id="highlighter_959048" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
protected
void
Page_Load(
object
sender, EventArgs e)
2
{
3
Response.StatusCode = 404;
4
Response.StatusDescription =
"Page not found"
;
5
Response.Flush();
6
}
Here is the problem: The code worked fine on my Windows 7 developer machine’s localhost, but when I copied the code to my Windows 2008 server, the IIS refused to call my custom page, displaying the default 404 error page instead.
Here is the catch: The Windows 2008 server is running the latest IIS 7.5, and this version will by default “override” the HTTP response with its default error pages if the page returns a HTTP error status code (like 404, or 500).
Here is the solution: .NET 3.5 has a new property calledResponse.TrySkipIisCustomErrors that will, if set to true, instruct IIS 7.5 to ignore it’s own default error pages, allowing me to use my own. The code change is very small, but highly effective:
<div id="highlighter_895425" class="syntaxhighlighter "> <div class="lines"> <div class="line alt1">1
protected
void
Page_Load(
object
sender, EventArgs e)
2
{
3
// Allow me to use my own error page:
4
Response.TrySkipIisCustomErrors =
true
;
5
Response.StatusCode = 404;
6
Response.StatusDescription =
"Page not found"
;
7
Response.Flush();
8
}