c# - 各种错误随机出现
问题描述
我决定修改这个问题,因为经过数小时的挫折,这是一项匆忙的工作。向所有浪费时间的人道歉。
拓扑:两种不同的应用。1. WPF 应用程序 C#。包括 DevExpress 工具、SignalR、Web api 的 AutoRest 实现。ADAL 身份验证。2. 驻留在 Azure 上的 Webapi ASP.NET,最近升级到 .net 版本 4.6.1(发布错误)。我也通过标题使用版本控制。3.Azure SQL Server作为后端。最近将 DTU(内存、CPU 等)从 10 升级到 20。(发布错误)
系统已经成功运行了大约三年,在此期间进行了大量的开发工作。
在几天没有发布之后,星期一早上来了,错误开始出现。我通过 NLog 将所有错误记录到 SQL Server。
第一个错误:(到目前为止我得到的最多)
System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: The decryption operation failed, see inner exception. ---> System.ComponentModel.Win32Exception: The specified data could not be decrypted
然后我开始看到
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
这个错误不太频繁,但昨天发生了 8 次。
我也看到了这个错误,今天我开始认为这可能是罪魁祸首。我将仔细查看我的 ADAL 呼叫,认为这一直运行良好。
Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'Unauthorized'
错误随机出现,您可以绕过它们,系统继续工作。经常需要刷新数据。
从那以后,我从我知道稳定的早期版本重建了 api,并添加了我此后创建的几个调用。我昨天重建了 WPF 应用程序,然后得到了相同的结果。
所以我开始认为它是 Azure 上的基础设施。
我升级了 SQL Server 上的 DTU(这已经达到顶峰,并且是必需的)。
我将 API Web 服务计划升级到一个新的级别。
我通过 Azure 将 api 上的最小 TLS 设置为 1.2。api 代码没有变化,我只是不知道 TLS 是如何工作的。
我现在有在 azure 上运行的应用程序洞察力,以查看 Web api 的运行情况,看看我是否能发现任何东西。
今天早上我仍然看到错误。这是漫长的一周!
解决方案
我将根据您提到的错误尝试帮助您。我正在努力解决同样的错误:
发送请求时出错。---> System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道。
考虑到您没有提供代码,我无法确定这是否是同一个问题,但基于错误,我建议您尝试以下操作:
在您的Global.asax
文件中,直接在Application_Start
方法中添加以下行:
ServicePointManager.SecurityProtocol =
((IEnumerable<SecurityProtocolType>)ConfigurationManager
.AppSettings["SecurityProtocol"]
.Split(',')
.Select(a => (SecurityProtocolType)Enum.Parse(typeof(SecurityProtocolType), a)))
.Aggregate<SecurityProtocolType, SecurityProtocolType>(0, (current, item) => current | (SecurityProtocolType)item);
在你的Web.config
:
<add key="SecurityProtocol" value="Tls12" />
在<appSettings>
节中。
这是另一个提到的 SecurityProtocol 错误,建议您在这里进行非常好的讨论。
推荐阅读
- string - 在 kotlin 中解析“value=1234; some other things”会更紧凑/更简洁
- javascript - 量角器测试 - 失败:javascript 错误:[$injector:modulerr]
- node.js - NodeJs - API 中的 Mongoose 查询仅在 Mocha Chai 测试中失败
- python-3.x - peewee,如何查询指定的表?
- go - 使用 golang 和并发验证 9x9 数独板
- r - R中的强制网络图
- opengl - 现代Opengl:旋转一个长方体,在长方体的一端有枢轴
- vb6 - VB6 Treeview Image Loop改变图像
- azure - 每个循环的逻辑应用程序以检测空白空间
- testing - 用于在我键入时显示在摘要窗格上的文本性能的 BDD 脚本