• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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

Hi,
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.

Thanks
0
ctudorprice
Asked:
ctudorprice
  • 2
  • 2
1 Solution
 
raterusCommented:
What about?

Response.StatusCode = 404
0
 
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.

0
 
raterusCommented:
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
http://www.wwwcoder.com/main/parentid/263/site/2295/68/default.aspx

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,
--Michael



0
 
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.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now