.net核心"Response.Cookies.Append"无法作为某些工作站使用 [英] .net core 'Response.Cookies.Append' not working as some station

查看:222
本文介绍了.net核心"Response.Cookies.Append"无法作为某些工作站使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用'Response.Cookies.Append'来设置ASP.NET Core 2.1文档(

I am using 'Response.Cookies.Append' for setting the culture as suggested in ASP.NET Core 2.1 docs (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.1#implement-a-strategy-to-select-the-languageculture-for-each-request).

在我的车站工作正常.但是当我的同事获取我的更改时,它不起作用.

And it is working perfectly fine at my station. But when my colleague fetches my changes, It is not working.

在调试过程中,我发现"Response.Cookies.Append"未添加Cookie.还有其他人遇到这个问题吗?有解决办法吗?

During debug, I found 'Response.Cookies.Append' didn't add the cookie. Anyone else meets the issue? Any solution?

推荐答案

您可能在ConfigureServices-Method的Startup.cs中具有已配置的CookiePolicyOption.

You might have a configured CookiePolicyOption in your Startup.cs in your ConfigureServices-Method.

services.Configure<CookiePolicyOptions>(options =>
  {
      // This lambda determines whether user consent for non-essential cookies is needed for a given request.
      options.CheckConsentNeeded = context => true;
      options.MinimumSameSitePolicy = SameSiteMode.None;
  });

如果是这样,您可以使用CookieOption.IsEssential = true设置cookie,如下所示:

If thats the case, you can set the cookie with the CookieOption.IsEssential = true like so:

var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions()
    {
      Path = "/", HttpOnly = false, IsEssential = true, //<- there
      Expires = DateTime.Now.AddMonths(1), 
    };

这篇关于.net核心"Response.Cookies.Append"无法作为某些工作站使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆