【发布时间】:2022-01-10 01:11:42
【问题描述】:
我的项目配置了 ASP.NET Core Web API。
我已经在 Startup.cs 文件中配置了这些设置:
配置服务:
services.AddSession(option=>{
option.IdleTimeout = TimeSpan.FromMinutes(2);
option.Cookie.HttpOnly = true;
option.Cookie.IsEssential = true;
});
配置:
app.UseSession();
注意:所有这些方法都在同一个控制器中。
在方法a中:
HttpContext.Session.SetString("key", "value");
在方法b中:
var session = HttpContext.Session.GetString(mobile);
但是运行后,会话变量输出为空,为什么?
【问题讨论】:
标签: asp.net-web-api asp.net-core-webapi