Cookie is not set when less than 1 year expires on localhost (Chrome and FF)

I ran into a problem on localhost, and in Chrome and Firefox , not Edge

this code will work fine and set a 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 Expires to just 300 days , the cookie will not be sent back to Request Cookies , (it will still appear in Response Cookies for a Change request)

Edit: this action is called via jquery ajax ( $.post ); and he worked, perhaps six months ago.

+6
firefox google-chrome asp.net-mvc asp.net-mvc-5
source share
1 answer

You tried to put cookie.Domain = null on localhost and use the domain name differently.

+1
source share

All Articles