I have a details page for products. The product is fetched by id in a query string, if a product with the id is found in the database we display the details, otherwise we show a "this item can not be found" message. Pretty standard stuff. What I would like to do is show the details page with the "this item can not be found' message but send a 404 response. This is so that Google will un-index items that have been removed.
So I have something like this(simplified):
<asp:Panel ID="pnlDetails" runat="server" Visible="false">
item details go here
</asp:Panel>
<asp:Panel ID="pnlError" runat="server" Visible="false">
<p>The specified item could not be found.</p>
</asp:Panel>
And in the code behind:
if(itemFound)
{
showDetails();
}
else
{
showError();
}
private void showDetails()
{
pnlDetails.Visible = true;
//fill in details
}
private void showError()
{
//set response
Response.StatusCode = 404;
pnlError.Visible = true;
}
What is happening now is I see the error panel but I still get a 200 response. Could anyone tell me what I am doing wrong? Any advice would be appreciated, thanks much!
Edit: This I am calling these methods in the Page_Load
event handler.