Cookies and ASP.NET Core

后端 未结 3 426
刺人心
刺人心 2020-12-06 05:54

This might be a simple question, I\'m hoping it is at least.

I\'ve started to look into the Release Candidate of ASP.NET Core and I can see that a lot of the configu

3条回答
  •  伪装坚强ぢ
    2020-12-06 06:44

    It's an old question, but I didn't see this answer anywhere so here goes.

    As for configuring the behavior of cookies globally you can do it in the Startup.

    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure(options =>
        {
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
            options.HttpOnly = HttpOnlyPolicy.Always;
            options.Secure = CookieSecurePolicy.Always;
            // you can add more options here and they will be applied to all cookies (middleware and manually created cookies)
        });
    
        ...
    }
    

    As for doing this in a manner that you have different configurations per environment I still haven't found a way of doing it myself.

提交回复
热议问题