当过期不到1年,在本地主机上的cookie没有被设置(Chrome和FF) [英] cookie not being set when Expires less than 1 year, on localhost (Chrome and FF)

查看:284
本文介绍了当过期不到1年,在本地主机上的cookie没有被设置(Chrome和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆