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

Posted on 2006-05-22
Last Modified: 2008-01-16
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.

Question by:ctudorprice
    LVL 33

    Expert Comment

    What about?

    Response.StatusCode = 404

    Author Comment

    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.

    LVL 33

    Accepted Solution

    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,


    Author Comment

    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.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now