I have a URL that looks like: /employees?employeeId=3992, which displays the employee with the ID 3992. That works fine and the HTTP Status Code is 200 OK.
However when someone writes an invalid ID in the URL such as: /employees?employeeId=39920, I would like my HTTP Handler to rewrite the path to our error page, and send HTTP Status Code 404.
Here's the code I'm using:
if (employee == null)
{
context.RewritePath("/error-page");
context.Response.StatusCode = 404; // if I remove this line, the error-page is displayed, and the StatusCode is 200.
}
When I set the HTTP Status Code to 404, the page displays this standard ASP.NET 404 error page.