.net core session的使用步驟
步驟 |
操作 |
備註 |
1 |
Microsoft.AspNetCore.Session Microsoft.AspNetCore.Http.Extensions |
nuget安裝包 |
2 |
ConfigureServices新增: services.AddDistributedMemoryCache().AddSession(), Configure新增:app.UseSession(); |
Startup.cs檔案中,AddDistributedMemoryCache()必須要有,開啟快取 |
3 | ConfigureServices中修改:options.CheckConsentNeeded = context => false; //注意這裡需要設定為false,預設為true | |
4 |
HttpContext.Session.SetString("access_token", value); HttpContext.Session.GetString("access_token"); |
設定session值 獲取值 |