当过期不到1年,在本地主机上的cookie没有被设置(Chrome和FF) [英] cookie not being set when Expires less than 1 year, on localhost (Chrome and FF)
问题描述
我面对本地主机上的一个问题,而在铬
和火狐
,而不是边
I'm facing a problem on localhost, and in Chrome
and Firefox
, not Edge
这code将工作正常,并会设置Cookie:
this code will work ok, and will set the cookie:
[HttpPost]
public ActionResult Change(string val)
{
var cookie = new HttpCookie(CookieName) { Value = val, Expires = DateTime.Now.AddYears(1) };
Response.Cookies.Add(cookie);
return Content("");
}
但是,如果我更改过期时间仅为 300天
,cookie将无法在请求中的Cookie发送回
,(它仍然是可见的响应cookie
为修改
要求)
however if I change the Expires to just 300 days
, the cookie won't be sent back in the Request Cookies
, (it will still be visible in the Response Cookies
for the Change
request)
编辑:
这个动作通过jQuery AJAX( $岗位
)调用;并用它也许工作一年半前
this action is called via jquery ajax ($.post
); and it used to work maybe half a year ago
推荐答案
你有没有试图把cookie.Domain = NULL在本地主机上并以其他方式使用该域名。
Have you tried to put cookie.Domain = null on localhost and use the domain name otherwise.
这篇关于当过期不到1年,在本地主机上的cookie没有被设置(Chrome和FF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!