ASP.NET Custom 404 Returning 200 OK Instead of 404 Not Found

前端 未结 7 558
Happy的楠姐
Happy的楠姐 2020-11-30 23:32

After trying to setup my site for Google Webmaster Tools I found that my Custom ASP.NET 404 page was not returning the 404 status code. It displayed the correct custom page

7条回答
  •  有刺的猬
    2020-12-01 00:14

    You can use the below code:

     Response.TrySkipIisCustomErrors = True
     Response.Status = "404 Not Found"
     Response.AddHeader("Location", "{your-path-to-your-404-page}")
    

提交回复
热议问题