Session
Prepare
public void ConfigureServices( IServiceCollection services ) { services.AddDistributedMemoryCache(); services.AddSession(options => { // Set a short timeout for easy testing. options.IdleTimeout = TimeSpan.FromSeconds(10); options.Cookie.HttpOnly = true; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure( IApplicationBuilder app, IHostingEnvironment env ) { .... app.UseSession(); app.UseMvc(); }
Using
[HttpGet("sysinfo/akka")] public String GetActorSystemInfo() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("akkainfo"))) { String systemInfo = _service.GetActorSystemInfo(); HttpContext.Session.SetString( "akkainfo", String.Format("{0} == {1}", systemInfo,DateTime.Now) ); } var systemInfo_cache = HttpContext.Session.GetString("akkainfo"); return systemInfo_cache; }