- 在你的项目上基于NuGet添加:
Microsoft.AspNetCore.Session
2.在startup.cs找到方法ConfigureServices(IServiceCollection services) 注入Session
services.AddSession();
3.在Configure(IApplicationBuilder app,…)中添加使用session中间件:
app.UseSession();
4.在控制器中设置和使用session
//写入session
HttpContext.Session.SetInt32("userId", 10);
//获取session
HttpContext.Session.GetInt32("userId");
以上是设置为整形 字符串类似