Base solution for your next web application
Open Closed

Using Redis with a Load Balancer #6142


User avatar
0
cmthomps created

We were having trouble with getting aspnetzero MVC/jQuery to work with redis behind a load balancer. We couldn't get it to work unless we used sticky sessions. We think we finally figured it out. We had to add the following code to persist the keys to redis in the startup.cs class:

if (_appConfiguration["Abp:RedisCache:PersistKeysToRedis"] != null && bool.Parse(_appConfiguration["Abp:RedisCache:PersistKeysToRedis"]))
            {
                var redis = ConnectionMultiplexer.Connect(_appConfiguration["Abp:RedisCache:ConnectionString"]);
                services.AddDataProtection()
                    .PersistKeysToRedis(redis, "DataProtection-Keys");
            }
            else
            {
                services.AddDataProtection().DisableAutomaticKeyGeneration();
            }

Is that the correct solution? If so, should I add it as an issue in github?


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @cmthomps

    We haven't tried using Redis with AspNet Zero using a load balancer. If it works for you, you can use this solution. You don't have to create an issue on AspNet Zero repository.

    If someone else faces the same problem, we can offer your solution.

  • User Avatar
    0
    VuCA created

    Hi @cmthomps,

    We use asp.net zero (version 5.4) with loadbalancer A10 - but only use persit source mode only. Can we use without persit source? They are

    Thanks!