【问题标题】:IIS 8.0 custom 404 not working! It returns 502 BAD GATEWAYIIS 8.0 自定义 404 不起作用!它返回 502 BAD GATEWAY
【发布时间】:2014-03-07 14:22:14
【问题描述】:

我有这个问题将近半年了,我的个人网站http://WayneYe.com部署在Windows azure上(C# 4.5,ASP.NET不是MVC,IIS 8.0),我咨询了很多SO线程,例如:

IIS7 custom 404 not showing

ASP.NET MVC 404 Error Handling

它们都不适合我的情况!我的 web.config 如下:

<customErrors mode="Off"></customErrors>

<httpErrors errorMode="Custom" existingResponse="Replace">
  <clear />
  <remove statusCode="404" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <remove statusCode="502" subStatusCode="-1" />
  <error statusCode="404" prefixLanguageFilePath="" path="~/404.aspx" responseMode="ExecuteURL" />
  <error statusCode="500" prefixLanguageFilePath="" path="~/500.aspx" responseMode="ExecuteURL" />
</httpErrors>

请不要告诉我使用“”

<customErrors mode="RemoteOnly" defaultRedirect="~/500.aspx">
      <error statusCode="404" redirect="~/404.aspx" />
    </customErrors>

"

它根本不工作!如果您尝试使用任何不存在的路径访问我的网站,您将收到 502 响应(而不是 404 响应)。例如:

Request URL:http://wayneye.com/dsgdsgfsdf
Request Method:GET
Status Code:502 Bad Gateway

Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:Wayne_SessionId=xtdiph5cz04e0tbsvl4bb2lw; WAWebSiteSID=d0762bbc4bf84201bfc0c7290b6ebad2;
Host:wayneye.com
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36

Response Headers
Content-Length:0
Date:Mon, 10 Feb 2014 10:00:58 GMT
Server:Microsoft-IIS/8.0

以下是从 HTTP 原始日志中挑选出来的:

2014-02-17 14:37:30 WAYNEYE GET /foo X-ARR-LOG-ID=4963d014-3330-440d-93de-a4344d5188d1 80 - 116.197.226.215 Mozilla/5.0+(Windows+NT+6.3; + WOW64)+为AppleWebKit / 537.36 +(KHTML,+等+壁虎)+镀铬/ 32.0.1700.107 + Safari浏览器/ 537.36 WAWebSiteSID = 8822178ae255478a8447b25a055a6422; + Wayne_SessionId = ypztkdccxub13ajwjo1yvmn4; + ARRAffinity = 11a7911d5cb3cbede8a042bc6547c4a522b36efb32d6fc5b60eacccf8b8db7f0; +的LoginName =韦恩; + __ atuvc = 0% 7C4%2C0%7C5%2C5%7C6%2C0%7C7%2C3%7C8 - wayneye.com 502 3 13 288 964 15

感谢任何帮助!

【问题讨论】:

  • 您可以使用 RDP 登录并检查 IIS 日志、事件日志等以获取有关错误的更多详细信息吗?您也可以尝试重新启动应用程序的主机?
  • 不,Azure 不提供 RDP。
  • 确实如此,也许您已禁用它。 msdn.microsoft.com/en-us/library/windowsazure/gg443832.aspx
  • 我刚刚在谷歌上寻找“502 BAD GATEWAY window azure”,发现这个链接可能对你有帮助:social.msdn.microsoft.com/forums/windowsazure/de-de/…
  • @ShashankChaturvedi 不! 502 发生在我的所有浏览器上!你可以在我的博客上尝试任何不存在的路径,无论你使用什么浏览器,你都会得到 502。

标签: asp.net http-status-code-404 iis-8


【解决方案1】:
【解决方案2】:

最终发现,在“&lt;httpErrors&gt;”部分,“路径”不能包含“~”!删除“~”404 重定向后,我在开发/生产环境中都可以使用。

我们想要的理想情况:

  • 开发模式下禁用 404/500重定向。
  • 生产模式下启用 404/500 重定向。

为此,最佳实践是在 web.Release.config 中“启用”404/500 重定向,请注意"xdt:Transform="Insert"”:

<httpErrors errorMode="Custom" existingResponse="Insert" defaultResponseMode="ExecuteURL" xdt:Transform="Insert">
  <clear />
  <remove statusCode="404" subStatusCode="-1" />
  <remove statusCode="500" subStatusCode="-1" />
  <error statusCode="404" path="/404.aspx" responseMode="ExecuteURL" />
  <error statusCode="500" path="/500.aspx" responseMode="ExecuteURL" />
</httpErrors>

所以在开发环境中(即web.debug.config),我们仍然可以得到默认的详细异常页面,而不是重定向到500:

<httpErrors errorMode="Detailed" existingResponse="Auto" />

【讨论】:

    猜你喜欢
    • 2019-12-15
    • 2020-06-14
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 2018-03-16
    • 2019-09-15
    • 2020-05-09
    相关资源
    最近更新 更多