我前段时间遇到过这个问题。它可能与新的 Cookie 政策有关。
尝试设置options.CheckConsentNeeded = context => false;
。所以在 Startup.cs 的“ConfigureServices”里面它需要是这样的:
public void ConfigureServices(IServiceCollection services)
{
var connection = Configuration["ConnectionStrings:DefaultConnection"];
services.AddDbContext<ProjectDbContext>(options => options.UseMySql(connection, b => b.MigrationsAssembly("PrimaryProject")));
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
//Here comes the change:
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(connection));
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddSessionStateTempDataProvider();
services.AddSession();
}
问候,
H·埃伯哈特