Why does asp.net go from doing normal 404 responses when there are no custom errors to responding with either 302 or 200 when you turn custom errors on?
So for example I've tried all of the following:
<customErrors defaultRedirect="Error.aspx" mode="Off">
<error statusCode="404" redirect="Error.aspx?status=404" />
</customErrors>
and
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error.aspx?status=404" responseMode="ExecuteURL" />
</httpErrors>
and
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/error.aspx?status=404" responseMode="Redirect" />
</httpErrors>
As far as I can tell the top one gives a 302 as it redirects to the error page, the second gives a 200 for some reason and the final one also give a 302. This seems rather silly as I still want a 404 (or whatever other error code) but to display a friendly message.
I realize I can send a different response back with my error page but that seems to give the 404 code to the error page and keeps the 302 on the original request.
Unless I'm missing something...
Steps for Custom Error PageAdd Web Form for custom error page. Set <customErrors> setting in Web. Config file of the application. Pass defaultRedirect and mode attributes in <customErrors>.
You are right, ASP.NET behaves a bit funky when customErrors
are enabled. In short, you can set redirectMode="ResponseRewrite"
for customErrors
and specifically set the response code in your error.aspx page.
I've blogged the details here: Keep ASP.NET error pages out of search engines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With