【问题标题】:The decryption operation failed, see inner exception解密操作失败,见内部异常
【发布时间】:2019-03-17 20:27:45
【问题描述】:

我正在使用 Visual Studio 2017 和 .NET Core 2.x。我已经建立了两个项目。第一个是后端 API (https://localhost:51637)。第二个是前端网站(https://localhost:54146)。前端网站调用后端API。它们都在我的机器上本地运行。

问题是,当前端尝试向 API 发送请求时,我得到了这个异常

info: Microsoft.AspNetCore.Server.Kestrel[20]
    Connection id "0HLKNTHFLCEA9" request processing ended abnormally.
System.IO.IOException: The decryption operation failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
    --- End of inner exception stack trace ---
    at System.Net.Security.SslStreamInternal.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer)
    at Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal.AdaptedPipeline.ReadInputAsync(Stream stream)
    at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
    at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
    at System.IO.Pipelines.Pipe.ReadAsync(CancellationToken token)
    at System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken cancellationToken)
    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.BeginRead(ValueTask`1& awaitable)
    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)

【问题讨论】:

    标签: api .net-core


    【解决方案1】:

    这个神秘的错误也可能发生在两个正在开发的 .NET Core 应用程序之间,其中 .NET 应用程序是您的自托管网站或 API,另一个是 .NET 客户端控制台应用程序或其他任何东西。

    服务器端错误是上面的OP转储,客户端错误是:

    System.Net.Http.HttpRequestException:无法建立 SSL 连接,请参阅内部异常。 ---> System.Security.Authentication.AuthenticationException: 根据验证程序,远程证书无效。

    运行此以信任开发证书并解决问题。

    dotnet dev-certs https -t -v
    

    更多信息在这里。

    https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx

    【讨论】:

      【解决方案2】:

      原来,我的浏览器 (Firefox) 不信任 API 证书。解决这个问题

      1. 在 API 项目 wwwroot 文件夹中创建一个空白的“index.html”页面(确保 API 项目设置为提供静态文件)
      2. 运行 API 项目
      3. 将浏览器指向 index.html 页面
      4. 将显示“您的连接不安全”的警告
      5. 点击“高级”和“添加例外”

      前端网站现在可以成功调用后端API了。

      【讨论】:

      • 通过在 Firefox 的地址栏中输入任何 https localhost API 端点来工作。
      猜你喜欢
      • 2014-03-02
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多