我有一个应用程序,我contanerized在Windows容器。
应用程序是调用另一个API服务的.NetFramework服务器。
我遇到了以下例外情况
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
在研究之后,我创建了一个证书并添加到我的Dockerfile中
下面是我的dockerfile
FROM mcr.microsoft.com/dotnet/framework/sdk:4.7.2-windowsservercore-ltsc2019 AS build
WORKDIR /app
COPY ./certs/ ./certs/
# Filepath refers to the path of cert files inside the container's file system
RUN powershell Import-Certificate -FilePath C:\certs\cert1.cer -CertStoreLocation Cert:\CurrentUser\My
# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore
# copy and build everything else
COPY . .
WORKDIR /app
RUN dotnet publish -c Release -o out --no-restore
FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2-windowsservercore-ltsc2019 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["win-container.exe"]
我错过什么了吗?
1条答案
按热度按时间liwlm1x91#
出现错误**
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
**的主要原因如下自签名证书无效证书损坏的证书
如果您使用的是自签名证书,并且它们未被识别,则可以跳过代码中的验证部分,或将其添加到受信任证书中。
如果您使用的是无效的证书(过期或从间歇性CA获取的证书),请尝试从受信任或标准CA供应商处生成新证书,并检查生成证书的主机名,即使host.example.com和example.com使用相同的主机名,也需要为它们生成单独的SSL证书。
有时,在复制或下载这些证书时,您可能会遇到一些问题,因为这些证书会被破坏或损坏,因此在使用这些证书时会产生问题。尝试各种方法复制这些证书,并在复制到目标后检查校验和。
希望这将有助于您解决您的问题。我附上几个链接,以供进一步参考
[1][https://www.limilabs.com/blog/the-remote-certificate-is-invalid-according-to-the-validation-procedure](https://www.limilabs.com/blog/the-remote-certificate-is-invalid-according-to-the-validation-procedure) [2] https://www.positioniseverything.net/the-remote-certificate-is-invalid-according-to-the-validation-procedure