aspnetcore 刷新Session Id总是改变

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddDistributedMemoryCache();
            services.AddSession(option =>
            {
                option.IOTimeout = TimeSpan.FromHours(1);
                option.IdleTimeout = TimeSpan.FromHours(1);
                option.Cookie.Name = "aiyu";
            });
        }

        // 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();
            }

            app.UseSession();
            app.UseMvc();
        }
    }
public ActionResult<IEnumerable<string>> Get()
        {
            HttpContext.Session.Set("a", Encoding.UTF8.GetBytes("ss"));
            return new string[] { "value1", HttpContext?.Session.Id};
        }

当Session保存有值,id才不会改变,没有值每次刷新都会变

原文地址:https://www.cnblogs.com/hanstar/p/10229460.html