首页 > 解决方案 > 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.

标签: azureredis

解决方案


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?


推荐阅读