出现“Asp.Net Core中的“aspnet-sessionId”无法正常工作”的问题通常是由于配置或代码错误导致的。以下是一些可能的解决方法和代码示例:
services.AddSession();
然后在Configure方法中添加以下代码来启用Session中间件:
app.UseSession();
services.Configure(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
HttpContext.Session.SetString("Key", "Value");
var value = HttpContext.Session.GetString("Key");
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:5000;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
}
希望以上解决方法能帮助您解决“Asp.Net Core中的“aspnet-sessionId”无法正常工作”的问题。如果问题仍然存在,请检查其他配置和代码是否有误,并查阅相关文档和资源以获取更多帮助。