Problem with defaultRedirect in Web.Config <customErrors>
I use Asp.net 4.
Here setting for my Web.Config
file.
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/ErrorPages/Oops.aspx">
<error statusCode="404" redirect="/ErrorPages/404.aspx" />
</customErrors>
I need to apply the defaultRedirect
url for any Exception, and use the redirectMode="ResponseRewrite"
for only Page Not Found 404.
With this setting at the moment I can manage properly the Page Not Found (I'm able to get the 404.aspx page) but if an exception arise on any other page I get the "Internet Explorer cannot display the webpage&q开发者_开发知识库uot;
and I'm not able to reach the defaultRedirect Oops.aspx
.
What I'm doing here wrong?
One problem with having an aspx page as the target of a custom errors redirect is that errors that aren't specific to a page (e.g. errors in global.asax; errors processing web.config) will also be thrown by the target page, which can result in an infinite redirect loop.
For this reason, it's often better to have a static html page as the target of at least the defaultRedirect.
Try putting the ~ in the redirect URL.
redirect="~/ErrorPages/404.aspx"
How many bytes is the error page content and does it set an HTTP status code other than 200 OK? In Internet Explorer with "Show friendly HTTP error messages" on, which is the default, custom error pages that have content under 512 bytes in length will be suppressed by the IE browser and replaced with the "friendly" error message.
To see if this is your problem, you can try turning off the "Show friendly HTTP error messages" option under Tools, Internet Options, Advanced, Settings. It'll be under the Browsing category in the Settings area.
If the page shows up with the option turned off, try turning it back on and changing your page to add an image or some other element that will make the size over 512 bytes long.
精彩评论