ServicePointManager.ServerCertificateValidationCallback 无法在 Windows Server 2012 R2 上运行
ServicePointManager.ServerCertificateValidationCallback not working on Windows Server 2012 R2
在我们的应用程序部署到我们的生产环境之前,我们从我们的 .NET Web 应用程序调用了较低环境中的一些 API。那些托管 API 的服务器往往没有由受信任的证书颁发机构签署的证书。
我创建了以下代码作为解决方法,在我们的生产环境中安全地排除了 运行 此代码:
if (ignoreCertErrors && environmentName.ToLower() != "PROD")
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}
ignoreCertErrors 和 environmentName 都是提供给包含此逻辑的方法的参数。
这适用于我的本地开发箱 (Windows 7),但是当我将它部署到 Windows 2012 R2 测试服务器时,我对具有不受信任的证书的 API 的调用仍然失败以下错误:
=================================================================
Message: The underlying connection was closed: An unexpected error
occurred on a send. Stack Trace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResultar)
=================================================================
Message: Unable to read data from the transport connection: An
existing connection was forcibly closed by the remote host. Stack
Trace:
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
=================================================================
Message: An existing connection was forcibly closed by the remote host
Stack Trace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
=================================================================
我是否需要更改此逻辑,或执行一些新操作以忽略 Windows Server 2012 R2 上的证书警告?
我将以不同的方式解决这个问题,我创建了一个与错误消息相关的 并征求解决建议。
在我们的应用程序部署到我们的生产环境之前,我们从我们的 .NET Web 应用程序调用了较低环境中的一些 API。那些托管 API 的服务器往往没有由受信任的证书颁发机构签署的证书。
我创建了以下代码作为解决方法,在我们的生产环境中安全地排除了 运行 此代码:
if (ignoreCertErrors && environmentName.ToLower() != "PROD")
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}
ignoreCertErrors 和 environmentName 都是提供给包含此逻辑的方法的参数。
这适用于我的本地开发箱 (Windows 7),但是当我将它部署到 Windows 2012 R2 测试服务器时,我对具有不受信任的证书的 API 的调用仍然失败以下错误:
================================================================= Message: The underlying connection was closed: An unexpected error occurred on a send. Stack Trace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResultar)================================================================= Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Stack Trace:
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)================================================================= Message: An existing connection was forcibly closed by the remote host Stack Trace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)=================================================================
我是否需要更改此逻辑,或执行一些新操作以忽略 Windows Server 2012 R2 上的证书警告?
我将以不同的方式解决这个问题,我创建了一个与错误消息相关的