当前位置: 代码迷 >> 综合 >> .NetCore 允许使用Session //报错信息:Session has not been configured for this application or request
  详细解决方案

.NetCore 允许使用Session //报错信息:Session has not been configured for this application or request

热度:83   发布时间:2023-12-01 12:44:42.0

//报错信息:Session has not been configured for this application or request

第一步:
Configure中添加

app.UseSession();

第二步:
ConfigureServices中
2.1修改代码:

options.CheckConsentNeeded = context => **false**;  
		    //这里也得改为false//将context => true改为false也行 可以理解成:可以存储cookie了 session和cookie是紧密联系的

2.2 加入以下代码

 services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(30);options.Cookie.HttpOnly = false;//options.Cookie.IsEssential = true;
});
  相关解决方案