什么会导致 GET 网络请求出现 "The certificate key algorithm is not supported" 异常

What could cause "The certificate key algorithm is not supported" exception on a GET web request

我们正在尝试使用标准网络请求从 asp .net MVC 4.6 应用程序连接到 facebook api。除了我们的一台服务器外,其他所有服务器都运行良好。有问题的服务器是 运行 windows 2012 和 IIS 8.

在这个特定的服务器上,当 运行 对 facebook 的 GET 网络请求时,我们得到以下异常。

The certificate key algorithm is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: The certificate key algorithm is not supported.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NotSupportedException: The certificate key algorithm is not supported.] System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) +409 System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) +213

[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +894 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +92

[HttpRequestException: An error occurred while sending the request.]
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +96 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +49

代码如下所示:

    // Request
    private static async Task<T> Request<T>(string url) where T : class
    {
        using (var handler = new WebRequestHandler())
        {
            handler.ServerCertificateValidationCallback = delegate { return true; };
            using (var client = new HttpClient(handler) { Timeout = System.TimeSpan.FromSeconds(20) })
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var result = await client.GetAsync(url);
                if (result == null) return null;
                var model = await result.Content.ReadAsAsync<T>();
                return model;
            }
        }
    }

我们绞尽脑汁想知道为什么除了我们的一台服务器之外,这在所有服务器上都有效。

有没有人知道什么可能导致此错误以及如何解决它。

谢谢。

我设法重现了这个问题,它似乎是网络跟踪中的错误,导致 X509Certificate2.ToString(true) 被设置,实习生抛出异常。

我找到的唯一解决方案是删除整个“System.Dianositics”部分,这将禁用日志记录。