Why does a nonexistent page return status 302 when using a custom 404 page in asp.net

I installed the custom 404 page custom404.aspx, which will return the "404 Not Found" error correctly, however the nonexistent page that was originally requested returns the status "302 Found".

So, when I test thispagedoesnotexist.aspx, it returns “302 Found”, then the user file 404.aspx loads and returns the status “404 Not Found”.

I want to make sure that search spiders / bots understand that the requested page does not exist and should not appear in search results. Is this setting correct?

+5
source share
4 answers

To answer this question, just how user errors work in ASP.NET. I saw examples (although I don’t have any convenient ones) where people used HttpModules to catch errors and serve a user error page for users who are not bots, and the answer to 404 users who appear to be bots.

In another direction, I'm not sure that bots regularly follow 302 responses. More appropriate, perhaps it is really so bad that your error page (if used) is displayed in the search results? At least the user has a link to your site - this is better than having your competitors site ...

0
source

, , web.config.

, - (IIS 6/7) 404 , !

asp.net/IIS . , , , :)

0

:

web.config "redirectMode = ResponseRewrite":

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/errors/GeneralError.aspx">
            <error statusCode="404" redirect="~/errors/PageNotFound.aspx" />
        </customErrors>

... 404 Page_Load put: this.Response.Status = "404 Not Found";

Voila!

0

...

:

/path_to_error_page.html 

... ...

http://www.example.com/path_to_error_page.html

The reason is that the server interprets the initial request, then generates a redirect to 404, so your client will effectively receive 2 responses.

Relative paths do not result in redirects, but transferring the internal server results in only 1 answer, the one you need !!

This should solve your problem.

-4
source

All Articles