tags:

views:

22

answers:

2

How can I configure ASP.NET/IIS to show custom error pages (i.e. a nice friendly error page), but to still return a 404/500 status code so that google does not try to index the page?

I have tried setting the Response.StatusCode to 404, but then the nice error page does not show anymore.

A: 

Add this line in you web.config file will do work

<customErrors> mode="RemoteOnly" defaultRedirect="ErrorPage.aspx" >
   <error statusCode="404" redirect="InternalError.htm"/>
</customErrors>

customErrors Element (ASP.NET Settings Schema)

Pranay Rana
Thanks pranay. Unfortunately the problem still remains. ASP.NET sends a 302 responseCode, which lets the users browser redirect to the error page. I actually want a real 404 error code to be returned, but to still display the nice error page to the user.
willem
just change status code to 302 will work for you but i think you find out y its returning 302
Pranay Rana
A: 

I have not tried this yet, but this page describes the exact issue and how to solve it. ASP.NET's way of returning 302's for error pages is a known SEO "issue".

http://weblogs.asp.net/paxer/archive/2010/05/31/asp-net-http-404-and-seo.aspx

willem