Server.TransferRequest() and the http status code

人盡茶涼 提交于 2019-12-04 05:44:27

Well, TransferRequest() triggers a new request, which implies a new response. Since the resource that PageNotFoundUrl points to does exist, the client receives a legitimate 200 OK status header.

You might want to write an HTTP handler (or handle an event in Global.asax) in order to force the status header to 404 Not Found when serving PageNotFoundUrl.

Server.TransferRequest doesn't change the status code. It passes control of the request on to another page without telling the client. You can manually set the status code in your custom 404 page in the Page_Load event:

protected void Page_Load(object sender, System.EventArgs e)
{
    Response.StatusCode         = 404;
    Response.StatusDescription  = "Not Found";
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!