title: Asp.Net Core 2.0 Load balance across servers
body: <p>I have my site load balanced across 10 servers.  It seems when the user gets switched between servers they have to log back in.  I am storing my machine keys and Session state in Redis.  The .AspNetCore.Identity.Application cookie exists and is not expired when they get logged out.  It seems that a cookie generated on one server is not being accepted on a different server.  Is there another setting I need to set for Load balancing?</p>
  
  <p>This is my ConfigureServices code.  </p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
  {
      services.AddIdentity&lt;Implementation.Core.IdentityUser, Implementation.Core.IdentityRole&gt;()
              .AddUserStore&lt;Implementation.UserStore&lt;Implementation.Core.IdentityUser, 
                                                     Implementation.Core.IdentityRole, 
                                                     Implementation.Core.UserClaim, 
                                                     Implementation.Core.UserLogin, 
                                                     Implementation.Core.UserRole&gt;&gt;()
              .AddRoleStore&lt;Implementation.RoleStore&lt;Implementation.Core.IdentityRole&gt;&gt;();
  
      services.AddScoped&lt;Microsoft.AspNetCore.Identity.IPasswordHasher&lt;Implementation.Core.IdentityUser&gt;, Implementation.PasswordHasher&gt;();
  
      services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
              .AddCookie(options =&gt;
              {
                  options.LoginPath = "/Login";
                  options.ReturnUrlParameter = "RedirectUrl";
                  options.LogoutPath = "/Login/Logout";
                  options.AccessDeniedPath = "/Login/AccessDenied";
              });
  
      services.ConfigureApplicationCookie(o =&gt;
      {
          o.ExpireTimeSpan = TimeSpan.FromMinutes(60);
          o.SlidingExpiration = true;
      });
  
      // Add framework services.
      services.AddMvc()
              .AddApplicationPart(typeof(Controllers.LocationController).Assembly)
              .AddApplicationPart(typeof(SysAdmin.Controllers.CommandController).Assembly)
              .AddApplicationPart(typeof(Supplier.Controllers.SupplierLocationController).Assembly)
              .AddApplicationPart(typeof(SpectacleCatalog.Controllers.LensDesignController).Assembly)
              .AddApplicationPart(typeof(Account.Controllers.CBUSearchController).Assembly);
  
      //services.AddDistributedMemoryCache();
  
  
      OutOfStateSettings outOfState = new OutOfStateSettings();
      Configuration.Bind("OutOfState", outOfState);
  
      services.AddDistributedRedisCache(opts =&gt;
      {
          opts.Configuration = outOfState.RedisIP;
          opts.InstanceName = outOfState.CacheId;
      });
  
      var redis = ConnectionMultiplexer.Connect($"{outOfState.RedisIP}:{outOfState.RedisPort}");
      services.AddDataProtection().PersistKeysToRedis(redis, outOfState.MachineKeyId);
      services.AddOptions();
  
      services.AddSingleton&lt;
          Microsoft.AspNetCore.Mvc.DataAnnotations.IValidationAttributeAdapterProvider,
          Util.CustomValidatiomAttributeAdapterProvider&gt;();
  
      services.AddSession(options =&gt;
      {
          options.IdleTimeout = TimeSpan.FromMinutes(120);
      });
  
      var builder = new ContainerBuilder();
      builder.Populate(services);
      this.ApplicationContainer = builder.Build();
      return new AutofacServiceProvider(this.ApplicationContainer);
  }
  </code></pre>