【问题标题】:Web Api returning 500 internal server errorWeb Api 返回 500 内部服务器错误
【发布时间】:2020-02-13 04:20:05
【问题描述】:

我正在敲打键盘,试图弄清楚为什么会发生这种情况。我正在 Swagger 进行测试(在本地运行应用程序)并获得 500 的回报。没有其他细节。我无法调试该问题,因为我无法在代码中命中任何断点。谁能从下面的代码中看出我的错误在哪里?

错误:

Response body
Download
{
  "StatusCode": 500,
  "Message": "Internal Server Error."
}
Response headers
 cache-control: no-cache 
 content-type: application/json 
 date: Wed, 12 Feb 2020 14:49:28 GMT 
 expires: -1 
 pragma: no-cache 
 server: Kestrel 
 status: 500 

代码:

[Route("api/v1/BusinessProcesses")]
        [ApiController]

        public class ProcessAssessmentController : EntityController<ProcessAssessment> {

            [AllowAnonymous]
            [HttpGet("{businessProcessId}/DocumentsDetails", Name = "GetDocumentDetailsSummary")]
            [ProducesResponseType(typeof(DocumentSummaryViewModel), StatusCodes.Status200OK)]
            [Produces("application/json")]
            [ProducesResponseType(StatusCodes.Status400BadRequest)]
            [ProducesResponseType(StatusCodes.Status403Forbidden)]
            [ProducesResponseType(StatusCodes.Status404NotFound)]
            [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
            [ProducesDefaultResponseType]
        public async Task<IActionResult> GetProcessDocumentDetails(string businessProcessId)
                {
                    <some details>.....

                    return Ok(documentSummary);
                }
        }

【问题讨论】:

  • 阅读How to Ask。调试你的代码。提供minimal reproducible example。您删除了相关代码。
  • 我发布了错误并在我的问题描述中给出了更详细的解释。对此感到抱歉。
  • 不,“500 内部服务器错误”只是“出现问题”的笼统陈述。调试您的代码,启用错误报告,添加日志记录。除了“问题很可能在&lt;some details&gt; 的某个地方”,我们什么也说不出来。
  • 关闭,但由于我在方法中的代码没有被执行,所以无法调试问题。这就是我如何知道它是方法调用之外的东西。

标签: asp.net-web-api


【解决方案1】:

问题是我没有在 Startup.cs 文件中注册我的控制器。我将它记录到 AppInsights 中,发现在我的构造函数中解决对服务的依赖存在问题。

【讨论】:

    猜你喜欢
    • 2017-10-28
    • 1970-01-01
    • 2012-05-05
    • 2017-08-26
    • 2020-10-13
    • 2016-04-02
    • 2018-09-30
    • 2021-03-25
    • 1970-01-01
    相关资源
    最近更新 更多