代码之家  ›  专栏  ›  技术社区  ›  Kevin Brydon

解密操作失败,请参阅内部异常

  •  0
  • Kevin Brydon  · 技术社区  · 6 年前

    我正在使用Visual Studio 2017和。网络核心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)
    
    1 回复  |  直到 6 年前
        1
  •  17
  •   Luke Puplett    6 年前

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

    服务器端错误与上面的OP dump一致,客户端错误为:

    系统网Http。HttpRequestException:无法建立SSL连接,请参阅内部异常--->系统安全认证。AuthenticationException:根据验证过程,远程证书无效。

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

    dotnet dev-certs https -t -v
    

    这里有更多信息。

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

        2
  •  7
  •   Kevin Brydon    6 年前

    事实证明,我的浏览器(Firefox)不信任API证书。要解决这个问题

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

    前端网站现在将能够成功调用后端API。