Redirect to 404error page YET return 404 Status Code

P

Pat Carden

I'm trying to provide a better user experience by redirecting my users to a
"Page Not Found" page, using a Custom Errors directive in Web.Config.

The problem is I need to return a 404 error code to the browser (or spider)
before redirecting. Now, the system is reporting a status code of 302 on
the original page and a 200 status code on the error page.

I would like to use Google Sitemaps and they require this, plus I have a
linkchecking service that is unable to detect the redirect.

Can someone tell me how to accomplish this? I tried with the following code
in the "Page Not Found" page, but it didn't yield the desired result.

Thanks a lot!

Pat
 
P

Pat Carden

In the PageNotFound page

I used

Response.StatusCode = 404

Doesn't seem to have the desired effect.

Pat
 
J

Juan T. Llibre

Have you tried using :

<customErrors mode="RemoteOnly" defaultRedirect="~/error.aspx">
<error statusCode="404" redirect="~/PageNotFound.aspx" />
</customErrors>

in your web.config ?
 
P

Pat Carden

Yes that's what I'm using but it return a status code 302 instead of a 404
and then a 200 when it hits the error page.
 
P

Patrick.O.Ige

Pat but if it returned status code 302 did it redirect you to the page you
specified?
Maybe check your IIS settings and see.
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top