【问题标题】:Hellang.Middleware.ProblemDetails does not display detail element after the project is publishedHellang.Middleware.ProblemDetails 项目发布后不显示细节元素
【发布时间】:2021-07-13 04:03:07
【问题描述】:

在开发环境中,错误显示为

{
    "type": "https://httpstatuses.com/401",
    "title": "Unauthorized",
    "status": 401,
    "detail": "LOGIN",  -- this is where I send detail of the error
    "errors": [
        {
            error-stack
        } ...

一旦发布,不仅errors元素丢失,就连detail也丢失了。

{
    "type": "https://httpstatuses.com/401",
    "title": "Unauthorized",
    "status": 401,
    "traceId": "|b1bda8d6-44744a1efb1ef714."
}

我怎样才能始终启用detail 元素?

【问题讨论】:

    标签: c# asp.net-core error-handling


    【解决方案1】:

    你好在startup.cs中注释这行代码

      if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
    

    然后在评论之后写下这一行

     app.UseDeveloperExceptionPage();
    

    现在您可以在真实服务器中看到异常了。

    【讨论】:

    • 我不想在生产中看到完整的错误堆栈,只想看到 detail 元素
    • 我觉得这个link可以帮助你
    猜你喜欢
    • 2018-07-31
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多