2012-12-04 44 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

是的可能。

如果小提琴手正在返回错误代码,应用程序将选择相同的。

相关问题