1.首先添加session包Microsoft.AspNetCore.Session
2.在start up文件里的ConfigureServices添加session,代码如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache().AddSession();
}
3.在Configure里面使用session,代码如下:
app.UseSession();
控制器调用:
set: HttpContext.Session.SetString("access_token", "session值");
get:HttpContext.Session.GetString("access_token");