title: Session id always changing for ASP.NET Core + Redis + nginx
body: <p>The sample project <a href="https://github.com/xingyu217/Redis-nginx-aspnetcore-session" rel="noreferrer">https://github.com/xingyu217/Redis-nginx-aspnetcore-session</a>
  nginx.config:</p>
  
  <pre><code>upstream study_server{
          server localhost:8011 weight=1;
          server localhost:8013 weight=1;
      #server localhost:8014 weight=1;
      #server 172.17.16.147:8012 weight=2;
      #server 172.17.16.147:8011 weight=2;
      }
      server {
          listen       80;
          server_name  localhost;
  
          #charset koi8-r;
  
          #access_log  logs/host.access.log  main;
  
          location / {
              #root   html;
              #index  index.html index.htm;
          proxy_pass http://study_server/;
              proxy_cookie_path ~*^/.* /;
          proxy_redirect off;
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
          }
  </code></pre>
  
  <p>Get session id: <strong>ViewBag.seId= HttpContext.Session.Id</strong>;</p>
  
  <p>Startup.cs:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
              {
                  // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                  options.CheckConsentNeeded = context =&gt; true;
                  options.MinimumSameSitePolicy = SameSiteMode.None;
              });
  
              //services.AddDistributedMemoryCache();
  
              services.AddDistributedRedisCache(options =&gt;
              {
                  options.Configuration = Configuration.GetConnectionString("RedisConnection");
                  options.InstanceName = "master";
              });
              services.AddSession(options =&gt;
              {
                  options.IdleTimeout = TimeSpan.FromSeconds(100);
                  //options.Cookie.HttpOnly = true;
              });
              //services.AddSession();
              services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
                  app.UseHsts();
              }
  
              //app.UseDeveloperExceptionPage();
              //app.UseHttpsRedirection();
              app.UseStaticFiles();
              app.UseCookiePolicy();
              app.UseSession();
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                      name: "default",
                      template: "{controller=Home}/{action=Index}/{id?}");
              });
          }
  </code></pre>
  
  <p>Access URL: localhost and refresh again and again, the session id will be always changing.</p>
  
  <p>I checked keys in redis server, it always generate the new key when refresh page. (e.g.masterdef69307-fbd3-c6ed-91d2-009b2306f902) </p>
  
  <p>If I just use a server (localhost:8011):</p>
  
  <pre><code>upstream study_server{
          server localhost:8011 weight=1;
          #server localhost:8013 weight=1;
      #server localhost:8014 weight=1;
      #server 172.17.16.147:8012 weight=2;
      #server 172.17.16.147:8011 weight=2;
      }
  </code></pre>
  
  <p>The session id won't be changed.</p>
  
  <p>Anyone know it will be appreciated. </p>
  
  <p>Thanks</p>