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才不會改變,沒有值每次刷新都會變

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM