0

运行以下代码以从我的 Azure 应用服务连接到 Azure 应用配置时,我收到以下“无法创建 SSL/TLS 安全通道”异常。

当我在我的开发机器(即连接到 Azure 应用程序配置的开发机器)上运行代码时,我没有问题。请注意,我的 App Service 是: Stack is .NET Framework Version ASP.NET 4.7

当我尝试使用 ManagedIdentityCredential 进行连接时,我得到了同样的错误。

var configurationRoot = configurationBuilder
                .AddAzureAppConfiguration(options =>
                {        
                    options
                        .Connect("Endpoint=blah;Id=blah;Secret=blah")
                        .Select(KeyFilter.Any, LabelFilter.Null)
                        .Select(prefix + ":*");
                }).Build();

导致此错误:

  The request was aborted: Could not create SSL/TLS secure channel.
    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.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
    
    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:
    
    
    [WebException: The request was aborted: Could not create SSL/TLS secure channel.]
       System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +54006511
       System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +83
    
    [HttpRequestException: An error occurred while sending the request.]
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__6.MoveNext() +434
    
    [RequestFailedException: An error occurred while sending the request.]
       Azure.Core.Pipeline.<ProcessAsync>d__6.MoveNext() +1073
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessNextAsync>d__10.MoveNext() +802
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__9.MoveNext() +2483
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__5.MoveNext() +763
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__3.MoveNext() +508
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__8.MoveNext() +612
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__7.MoveNext() +508
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__6.MoveNext() +1112
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Azure.Core.Pipeline.<ProcessAsync>d__11.MoveNext() +689
    
    [AggregateException: Retry failed after 3 tries.]
       Azure.Core.Pipeline.<ProcessAsync>d__11.MoveNext() +1410
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<ProcessAsync>d__2.MoveNext() +598
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<ProcessAsync>d__1.MoveNext() +513
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Core.Pipeline.<SendRequestAsync>d__10.MoveNext() +570
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Azure.Data.AppConfiguration.<GetConfigurationSettingsPageAsync>d__42.MoveNext() +2153
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Azure.Core.<AsPages>d__2.MoveNext() +479
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) +119
       Azure.<GetAsyncEnumerator>d__6.MoveNext() +1338
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Azure.<GetAsyncEnumerator>d__6.MoveNext() +1895
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.GetResult(Int16 token) +119
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<<LoadAll>b__4>d.MoveNext() +783
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<<LoadAll>b__4>d.MoveNext() +1278
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<CallWithRequestTracing>d__4.MoveNext() +809
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<CallWithRequestTracing>d__23.MoveNext() +310
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<LoadAll>d__15.MoveNext() +1606
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       Microsoft.Extensions.Configuration.AzureAppConfiguration.<LoadAll>d__15.MoveNext() +2641
       System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
       System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
       Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.Load() +429
       Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers) +292
       Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() +249
4

2 回答 2

2

基于 .NET Framewok 4.7+ 构建的应用程序使用操作系统设置来确定 SSL/TLS 连接的默认安全协议。由于应用配置服务器不支持应用服务使用的 SSL/TLS 的默认版本,因此收到错误。

可以使用此处所述的注册表设置来配置默认安全协议。对于应用服务,实施推荐标准的一种便捷方法TLS 1.2是通过 Azure 门户中应用服务资源的 TLS/SSL 设置窗格。

Azure 门户中的 TLS/SSL 设置

根据有关 TLS 最佳实践的 Microsoft文档,建议不要在 .NET Framework 应用程序中指定 TLS 版本。

.NET Framework 的 TLS 最佳实践

于 2020-08-21T23:03:15.813 回答
0

我通过将以下内容添加到 AppService 上的 global.asax.cs 解决了这个问题。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我想我想了解为什么强制使用 TLS 1.2 有效。无论如何,希望这对某人有所帮助。

于 2020-08-21T17:49:12.383 回答