使用ASP.NET Framework 4.6.1和Chrome时,未将Cookie设置到已部署的网站中

问题描述

未在Chrome中设置Httpcookie。它在Mozilla浏览器中按预期工作。我们正在使用.NET Framework 4.6.1。

我们在web.config中编写了以下重写规则:

<rewrite>
  <outboundRules>
    <rule name="Add SameSite" preCondition="Lax SameSite">
      <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
      <action type="Rewrite" value="{R:0}; SameSite=Lax" />
      <conditions>
      </conditions>
    </rule>
    <preConditions>
      <preCondition name="Lax SameSite">
        <add input="{RESPONSE_Set_Cookie}" pattern="." />
        <add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=Lax" negate="true" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

我们正在使用以下代码设置Cookie

public void Set(string key,string value,int expireHours = 1)
{
    HttpCookie cookie = HttpContext.Current.Request.Cookies[Constants.CookieName];

    if (cookie == null)
        cookie = new HttpCookie(Constants.CookieName);

    cookie.Secure = true;
    cookie.Expires = DateTime.Now.AddHours(expireHours);
    cookie[key] = value;

    HttpContext.Current.Response.Cookies.Add(cookie);
}

但是,如果我将localhost的Secure属性设置为false,它就可以正常工作。由于我们的网站托管在HTTPS上,因此我添加了cookie.Secure = true;但是,这无法在chrome浏览器中使用。我们目前无法更新ASP.NET框架。

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...