I am trying to use custom error pages using redirects in IIS7. This is my code:
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Pages/NotFound" responseMode="ExecuteURL" />
</httpErrors>
As you can see the line <remove statusCode="404" subStatusCode="-1" />
resets the status code and when I hit the page I get a Status Code of 200 for a page that is not found. Is that really the right way to handle pages that are not found?
My understanding is that I would want to return 404 errors even when I show a nice page from within my site for pages that don't exist. I know this is an edge case but I am trying to cover all of my bases.
the page I am redirecting to is an .aspx page and has c# code behind it. In the page I am putting:
protected void Page_Load(object sender, EventArgs e)
{
Response.Status = "404 Not Found";
}
This code does not appear to actually do anything though. Does anyone have any guidance on if I should be returning 404 Errors and if so how to do it? Thanks.