azure - Cannot connect to Azure Redis after changing Minimum TLS version to 1.2
问题描述
In my .NET Framework 4.6.1 application I am using StackExchange.Redis.StrongName 1.2.6 to connect to Azure Redis. This is the code
public RedisContext(string connectionString = null)
{
if (connectionString == null) return;
Lazy<ConfigurationOptions> lazyConfiguration
= new Lazy<ConfigurationOptions>(() => ConfigurationOptions.Parse(connectionString));
var configuration = lazyConfiguration.Value;
configuration.SslProtocols = SslProtocols.Tls12;//just added
configuration.AbortOnConnectFail = false;
Lazy<ConnectionMultiplexer> lazyConnection =
new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configuration));
_connectionMultiplexer = lazyConnection.Value;
LogProvider.IsDisabled = true;
var connectionEndpoints = _connectionMultiplexer.GetEndPoints();
_lockFactory = new RedisLockFactory(connectionEndpoints.Select(endpoint => new RedisLockEndPoint
{
EndPoint = endpoint,
Password = configuration.Password,
Ssl = configuration.Ssl
}));
}
In Azure, I have changed the Redis resource to use TLS1.2 and in code I have added this line:
configuration.SslProtocols = SslProtocols.Tls12;//just added
And now, nothing works anymore. This is the error I get in Application Insights:
Error connecting to Redis. It was not possible to connect to the redis server(s); ConnectTimeout
I have also tried to add ",ssl=True,sslprotocols=tls12" to the redis connection string, but with the same result.
解决方案
Try referencing StackExchange.Redis instead of StackExchange.Redis.StrongName. I have done that in a few of my projects and now it works. However some 3rd party still use StrongName rather than the normal redis one. StackExchange.Redis.StrongName is now deprecated. https://github.com/Azure/aspnet-redis-providers/issues/107. I assume you are trying to connect to Azure Redis in relation to them stopping TLS 1.0 and 1.1 support?
推荐阅读
- javascript - 从文本框中获取值不会给出单行字符串?
- php - 连接错误 08001:[unixODBC][Teradata][ODBC] (10380) 无法与数据源建立连接。缺少设置:PHP 中的 {[DBCName]}
- redis - RedisInsight:redis 实例不支持“MEMORY”命令
- python - 如何在基于 Django 类的视图中限制用户组的访问?
- delphi - 代码取一个值并随机/“不相等”地划分它。我怎样才能让它适用于实数/十进制值?
- javascript - Angular子组件重新加载放置在ngif div中的所有内容
- python - 检查交易组之间的值是否发生变化
- java - 验证对象不接受数据类型的 SPRING 函数
- angular - 未定义 fetchCompletion 中的错误 - Angular 10 Visual Studio 代码
- ios - 将按钮添加到显示另一个模态视图控制器的自定义单元格