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

前端 未结 7 647
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-11-30 23:51

    After much testing and troubleshooting it appears that certain hosting providers can interfere with the return code. I was able to get around this by applying a "hack" in the content.

    <%
    // This code is required for host that do special 404 handling...
    Response.Status = "404 Not Found";
    Response.StatusCode = 404;
    %>
    

    This will allow the page to return the correct return code no matter what.

提交回复
热议问题