为了解决ASP.Net Core 6.0中Session在iframe中不能保持的问题,可以尝试以下几种方法:
1.在启用了Session的Endpoint配置中添加RequireCors:
services.AddSession(options =>
{
options.Cookie.IsEssential = true;
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
services.AddCors(); //添加Cors
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireCors("AllowAll");
});
3.将Session配置从UseMvc改为UseRouting和UseEndpoints:
app.UseRouting();
app.UseSession();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
通过使用以上解决方法之一,ASP.Net Core 6.0中Session在iframe中的问题应该会得到修复。
上一篇:ASP.NETCore6.0中IAntiforgery出现问题
下一篇:ASP.NETCore6.0中使用EntityFramework版本6,在执行Add-Migration命令后未能在SQLServer中创建数据库