cookie not being set when Expires less than 1 year, on localhost (Chrome and FF)

感情迁移 提交于 2019-12-22 05:26:34

问题


I'm facing a problem on localhost, and in Chrome and Firefox, not Edge

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("");
}

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)

Edit: this action is called via jquery ajax ($.post); and it used to work maybe half a year ago


回答1:


Have you tried to put cookie.Domain = null on localhost and use the domain name otherwise.



来源:https://stackoverflow.com/questions/37048556/cookie-not-being-set-when-expires-less-than-1-year-on-localhost-chrome-and-ff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!