jgd1234567
Programmer
Hi, I'm trying to make my site more search engine friendly by correctly handling 404 error pages. I have the following in my web.config file:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error/500.htm">
<error statusCode="500" redirect="~/Error/500.htm"/>
<error statusCode="404" redirect="~/Error/404.htm"/>
</customErrors>
This works most of the time but sometimes a user enters a url ie /forum/viewpost.aspx?postid=99 and although the viewpost.aspx page exists i want to throw a 404 error. I figured i could do a redirect to my 404 page (if the post could not be found) and then manually update the header status code in my 404 page, like so:
protected void Page_Load(object sender, EventArgs e)
{
// Add response header
Response.Buffer = true;
Response.StatusCode = 404;
Response.Status = "404 Not Found";
}
But this keeps returning a status code of 302. I have tried commenting out the response.buffer line but this did not work either.
Really appreciate if someone could help. Thanks
<customErrors mode="RemoteOnly" defaultRedirect="~/Error/500.htm">
<error statusCode="500" redirect="~/Error/500.htm"/>
<error statusCode="404" redirect="~/Error/404.htm"/>
</customErrors>
This works most of the time but sometimes a user enters a url ie /forum/viewpost.aspx?postid=99 and although the viewpost.aspx page exists i want to throw a 404 error. I figured i could do a redirect to my 404 page (if the post could not be found) and then manually update the header status code in my 404 page, like so:
protected void Page_Load(object sender, EventArgs e)
{
// Add response header
Response.Buffer = true;
Response.StatusCode = 404;
Response.Status = "404 Not Found";
}
But this keeps returning a status code of 302. I have tried commenting out the response.buffer line but this did not work either.
Really appreciate if someone could help. Thanks