问题描述
未在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 (将#修改为@)