【问题标题】:How to determine the cause of 500 error如何确定 500 错误的原因
【发布时间】:2017-04-08 20:39:31
【问题描述】:

我正在使用 IIS Express 和我制作的 ASP.NET Core 应用程序。在我最近的变更集中,我开始得到

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

在客户端。我可以在事件查看器中做任何事情,服务器日志也没有真正给我任何有用的信息

#Date: 2017-04-08 04:24:20
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2017-04-08 04:24:20 ::1 DEBUG / - 60372 - ::1 - - 200 0 64 19049
2017-04-08 04:24:28 ::1 GET / - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 23321
2017-04-08 04:24:30 ::1 GET /js/tutorial.jsx - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://localhost:60372/ 404 0 0 2764
2017-04-08 04:24:49 ::1 GET /comments - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 341
2017-04-08 04:25:02 ::1 GET / - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 580
2017-04-08 04:25:02 ::1 GET /js/tutorial.jsx - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://localhost:60372/ 404 0 0 1026
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2017-04-08 04:36:21
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2017-04-08 04:36:21 ::1 DEBUG / - 60372 - ::1 - - 200 0 64 20554
2017-04-08 04:36:30 ::1 GET / - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 25434
2017-04-08 04:36:34 ::1 GET /js/tutorial.jsx - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://localhost:60372/ 404 0 0 3737
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2017-04-08 04:38:28
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2017-04-08 04:38:28 ::1 DEBUG / - 60372 - ::1 - - 200 0 64 9241
2017-04-08 04:38:38 ::1 GET / - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 16824
2017-04-08 04:38:43 ::1 GET /js/tutorial.jsx - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://localhost:60372/ 200 0 0 6067
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2017-04-08 04:41:07
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2017-04-08 04:41:07 ::1 DEBUG / - 60372 - ::1 - - 200 0 64 27826
2017-04-08 04:41:20 ::1 GET / - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 38678
2017-04-08 04:41:34 ::1 GET /js/tutorial.jsx - 60372 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://localhost:60372/ 200 0 0 12721
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0

我发现如果我从Index.cshtml 中注释掉@Url.Content("~/js/tutorial.jsx")

@{
    Layout = null;
}
<html>
<head>
    <title>LRC Archive Dashboard</title>
</head>
<body>
    <div id="content"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js"></script>
    <script src="@Url.Content("~/js/tutorial.jsx")"></script>
</body>
</html>

我的变更集是https://github.com/jamkin/archivedash/commit/6bde62f9c85d3e8b0e32d1fb83e5737f91050e0e,对我来说它在那之前就可以工作。

我已经通过Startup.cs 和我的控制器进行了调试(当我访问页面时它会被实例化)并且没有异常。

有人可以帮我指出问题的方向吗?

【问题讨论】:

  • 这是一些服务器端错误(如 500 代码所示)。我没有从您发布的内容中获得足够的信息,无法为您提供比这更好的信息。我建议向服务器添加更多日志记录以查看失败的位置。
  • 这并不能解决您的问题,但您确实应该使用 MVC Core 为您提供的内置依赖注入框架。
  • 哦,既然您在 MVC Core 中,请考虑包含您的 Javascript 文件,例如 &lt;script src="~/js/tutorial.jsx" asp-append-version="true"&gt;&lt;/script&gt;

标签: asp.net .net reactjs iis asp.net-core


【解决方案1】:

由于错误“加载资源失败:服务器响应状态为500(内部服务器错误)”来自客户端,您是否可以查看开发人员工具栏的网络选项卡以查看详细的错误响应来自服务器。

在您粘贴的 IIS 日志中,我没有看到 500 响应状态。由于您正在使用 localhost(从 iis 日志中找到它),服务器应该发送带有堆栈和其他详细信息的详细错误响应。希望您已按照 here 的说明在 Configure 方法中启用添加开发人员异常页面

if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

在您的客户端,您可以检查开发人员工具栏->网络选项卡->单击 500 错误

您可以在 IE/Chrome/Firefox 等中看到类似的响应详情

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2011-11-26
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多