我在DiscountASP.NET上託管我的網站。我最近遇到了404錯誤處理方面的問題,因爲客戶端並沒有發送404狀態碼,我無法弄清楚爲什麼它突然出現。它曾經工作。 我試着通過一個簡單的例子開始解決我的錯誤處理代碼。我有兩個頁面,這兩個頁面都存在:ASP.NET 404處理代碼在本地但不在服務器上工作
404_start.aspx:此頁面旨在模擬不存在的頁面。
<%@ Page Language="C#" Debug="True" Strict="True" %>
<script runat="server">
public void Page_Load()
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 404;
Response.Status = "404 Not Found";
Server.ClearError();
Server.Transfer("404_end.aspx");
}
</script>
<html>
<body>
Start
<br />Response.StatusCode: <%=Response.StatusCode%>
<br />Response.Status: <%=Response.Status%>
</body>
</html>
404_end.aspx:此頁面是爲了模擬用戶看到錯誤消息。
<%@ Page Language="C#" Debug="True" Strict="True" %>
<html>
<body>
End
<br />Response.StatusCode: <%=Response.StatusCode%>
<br />Response.Status: <%=Response.Status%>
<br />This is extra text to fix this bug in Internet Explorer: http://queenofsubtle.com/404/?page_id=2158
<br />This is extra text to fix this bug in Internet Explorer: http://queenofsubtle.com/404/?page_id=2158
<br />This is extra text to fix this bug in Internet Explorer: http://queenofsubtle.com/404/?page_id=2158
<br />This is extra text to fix this bug in Internet Explorer: http://queenofsubtle.com/404/?page_id=2158
</body>
</html>
所以一開始頁面重定向到尾頁,但404錯誤永遠不會到來通過。 Fiddler說這是一個302,然後是200.但404_end.aspx頁面實際上讀取的是「Response.StatusCode:404」。 在本地,Fiddler根據需要看到404錯誤。 它可能是主機的錯?謝謝。