原文链接:https://zhuanlan.zhihu.com/p/637395503
1,在ConfigureServices方法里加入services.AddSession() 配置
public void ConfigureServices(IServiceCollection services)
{
services.AddSession();
}
2,在Configure 里介入app.UseSession() 配置
注意app.UseSession();这句要加在前面,要不不管用
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
app.UseSession();
}
3,设置session、读取session
public async Task<ActionResult> Query()
{
HttpContext.Session.SetString("queryPwd", "11");
ViewBag.queryPwd = HttpContext.Session.GetString("queryPwd")??"";
return View();
}
以上就是在net core 中使用session 的过程
标签:core,app,queryPwd,session,net,public From: https://www.cnblogs.com/Dongmy/p/18279322