gpt4 book ai didi

未在 Edge(点网核心)上设置 session cookie

转载 作者:行者123 更新时间:2023-12-03 16:04:02 26 4
gpt4 key购买 nike

session cookie 在 Chrome、FireFox 甚至 IE 上设置,但不在 Edge 上设置

浏览器版本为 Microsoft Edge 42.17134.1.0
DotNet 核心版本是 2.1
以下信息用于我的 startup.cs文件

 public void ConfigureServices(IServiceCollection services) {
services.Configure < CookiePolicyOptions > (options => {
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonOptions(options => {
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
}).AddSessionStateTempDataProvider();

services.AddDistributedMemoryCache();

services.AddSession(o => {
o.IdleTimeout = TimeSpan.FromMinutes(80);
o.Cookie.HttpOnly = true;
o.Cookie.Name = "my-session-cookie";

});
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
} else {
app.UseExceptionHandler("/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseSession();

app.UseSpaStaticFiles();

app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});

app.UseSpa(spa => {
spa.Options.SourcePath = "ClientApp";

if (env.IsDevelopment()) {
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}

以下是我迄今为止尝试过的一些方法:
  • 添加 IsEssential session 选项的条件
  • 删除 CookiePolicyOptionsUseCookiePolicy
  • 试图给 session cookie 添加过期日期(甚至没有启动解决方案)
  • 最佳答案

    使用 fetch边缘 导致 set-cookie不在浏览器上设置 cookie 的 header

    解决方案是添加 credentials: "same-origin"fetch选项对象

    请勿将其添加到标题

    引自 HERE

    By default, fetch won't send or receive any cookies



    这意味着您已向其添加凭据对象,以便它可以设置这些 cookie

    Since Aug 25, 2017. The spec changed the default credentials policy to same-origin.



    我猜 边缘 尚未实现该默认值

    这是一个工作示例 fetch
    fetch(link, {
    body: JSON.stringify(myDataObject),
    method: "POST",
    credentials: "same-origin",
    headers: {
    "content-type": "application/json"
    }
    });

    关于未在 Edge(点网核心)上设置 session cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54875392/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com