A REAL "404 Not Found" response in ASP.NET?

I want to create a 404 page that really sends a "404 Not Found" status that includes custom content.

Problem is that when CustomErrors is on in web.config, the errorhandling actually sends a 302 response and redirects the browser using 'Location: /mycustom404.aspx?aspxerrorpath=/asdffd.aspx' in the header. Problem with this is that I want to send Google et. al. a real "404 Not Found" status, not a "302 Found" status but I also want the page to be user-friendly and not rely on the generic 404 IIS page. I tried putting response.status="404 Not Found" on my custom404.aspx page, but all that does is tell Google that the custom404.aspx page can't be found, not the original.

Anyone have any ideas? I want Google and others to de-index pages that don't exist (thus avoiding possible duplicate content issues) but I don't want stranded users.

Who is Participating?
raterusConnect With a Mentor Commented:
Interesting dilemma, I can understand not wanting the redirect, as that means nothing to a search engine bot to get the 404 after-the-fact.

I guess you want the user to see the custom redirect page contents, but the contents of that should be the first and only response they see along with a 404 status code.

Might I suggest this article, at least the end of it

It's not geared exactly to what you want, but the fix for you should be simple.  

#1) Remove any web.config settings to redirect on a 404 error  

#2) Read the bottom two paragraphs about how to configure IIS/404, and tell IIS to use your existing page you created for any 404 requests.

This should work,

What about?

Response.StatusCode = 404
ctudorpriceAuthor Commented:
tried that - same effect ast the response.status="404 Not Found".

iis doesn't find a page on my site and thus looks in web.config to see if I have custom errors. If configured, it redirects the user to that page, using the 302 and a location. I can send a 404 then but that only indicates that the custom error page was not found, not the originally requested page.

ctudorpriceAuthor Commented:
Thanks - I vaguely remember trying this (or a similar approach) and I found that when I configured the IIS 404 to execute my .aspx, it was executed out-of-process - or session - which was a bit of a drag. But I'll try this again - maybe I was doing something wrong. Thanks. I'll let you know how it goes.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.