这是什么原因"该证书密钥算法是不支持"在一个GET Web请求例外 [英] What could cause "The certificate key algorithm is not supported" exception on a GET web request

查看:574
本文介绍了这是什么原因"该证书密钥算法是不支持"在一个GET Web请求例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图从使用标准的WebRequest一个的ASP.NET MVC 4.6应用程序连接到Facebook的API。一切都适用于所有,但我们的服务器之一的罚款。有问题的服务器运行的是Windows 2012和IIS 8。

We are trying to connect to the facebook api from a asp .net MVC 4.6 app using a standard webrequest. Everything works fine on all but one of our servers. The server in question is running windows 2012 and IIS 8.

在运行GET WebRequest的Facebook的时候,我们得到以下异常这一特定的服务器。

On this particular server we get the following exception when running a GET webrequest to facebook.

不支持该证书密钥算法

说明:$的执行过程中发生未处理的异常b $ b将当前Web请求。请查看有关错误的更多
信息的堆栈跟踪以及它起源于代码。

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.

异常详细信息:System.NotSupportedException:不支持的证书密钥
算法

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

来源错误:


当前Web请求的执行过程中生成了未处理的异常。 。关于$ B $的起源和地点B中的异常可以使用下面的异常堆栈跟踪信息确定信息

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.

堆栈跟踪:

[NotSupportedException异常:是不是
支持的证书密钥算法] System.Net.TlsStream.EndWrite(IAsyncResult的asyncResult)
409 System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult的AR) +213

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

[引发WebException:基础连接已关闭:上一个发送发生意外的
错误]结果
System.Net。 HttpWebRequest.EndGetResponse(IAsyncResult的asyncResult)
894 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult的AR)
+92

[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:在发送请求时发生错误。]结果
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+32结果
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务
任务)+96 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
+49

[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;
            }
        }
    }

我们都挠头的为什么这适用于所有,但我们的服务器之一。

We are scratching our heads as to why this works on all but one of our servers.

有没有人有什么可能导致此错误以及如何解决它的任何想法。

Does anyone have any ideas what might cause this error and how to resolve it.

感谢。

推荐答案

我设法复制的问题,它似乎是在网络跟踪的bug这将导致X509Certificate2.ToString(真)要设置哪些实习生抛出异常。

I managed to replicate the problem and it appears to be bug in network tracing which causes X509Certificate2.ToString(true) to be set which intern throws the exception.

我已经找到了唯一的解决方法是删除整个System.Dianositics部分,将禁用日志记录。

The only solution I have found is to delete the whole ‘System.Dianositics’ section which will disable the logging.

这篇关于这是什么原因&QUOT;该证书密钥算法是不支持&QUOT;在一个GET Web请求例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆