2012-12-04 48 views
0

我在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錯誤。 它可能是主機的錯?謝謝。

回答

0

我想我已經想通了。這是我的web.config文件的壓縮版:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <customErrors mode="On" defaultRedirect="~/error/default.aspx" redirectMode="ResponseRewrite"> 
     <error statusCode="404" redirect="~/error/404.aspx" /> 
    </customErrors> 
    </system.web> 
    <system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="Redirect to HTTPS" stopProcessing="true"> 
      <match url=".*" /> 
      <conditions> 
      <add input="{HTTPS}" pattern="^OFF$" /> 
      <add input="{HTTP_HOST}" pattern="192\.168\." negate="true" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}{PATH_INFO}" redirectType="SeeOther" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 

看來重寫規則和進行的customErrors互動。當我刪除上面顯示的重寫規則(這意味着當用戶請求http時強制https),服務器又開始返回404錯誤。所以我在C#中實現了http-> https開關,而不是web.config文件,並且一切似乎都很好。由於http-> https切換是在Web上執行的,因此問題不在本地顯示。問題顯然不是DiscountASP.NET的錯,儘管對於我來說沒有意義,爲什麼我不應該使用customErrors標記的重寫規則。

0

是的可能。

如果小提琴手正在返回錯誤代碼,應用程序將選擇相同的。

相關問題