zoukankan      html  css  js  c++  java
  • 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才不会改变,没有值每次刷新都会变

  • 相关阅读:
    【转】C++11优化使用emplace,emplace_back
    面试经历总结
    Hive常用函数
    股票指标
    Visual Studio Code 可以翻盘成功主要是因为什么?
    openpyxl模块操作Excel
    JavaScript(二)
    前端之CSS
    ps导出ICO格式
    Qt 所有版本官方下载地址
  • 原文地址:https://www.cnblogs.com/hanstar/p/10229460.html
Copyright © 2011-2022 走看看