【问题标题】:Cookie alive after delete on ajax requests删除 ajax 请求后 Cookie 还活着
【发布时间】:2021-03-22 22:55:50
【问题描述】:

我有这个方法可以从响应和请求中清除我的 cookie:

    public static void Clear()
    {
        var cookies = HttpContext.Current.Response.Cookies;

        cookies.Add(new HttpCookie("notification-status") { Expires = DateTime.Now.AddYears(-2) });
        cookies.Add(new HttpCookie("notification-message") { Expires = DateTime.Now.AddYears(-2) });

        var cookies2 = HttpContext.Current.Request.Cookies;

        cookies2.Add(new HttpCookie("notification-status") { Expires = DateTime.Now.AddYears(-2) });
        cookies2.Add(new HttpCookie("notification-message") { Expires = DateTime.Now.AddYears(-2) });
    }

使用此 cookie 后,我调用此方法,在浏览器检查器中,cookie 似乎已被删除,但是当我在 ajax 上发出请求时,cookie 似乎是活动的,两次显示通知。

【问题讨论】:

    标签: asp.net asp.net-mvc cookies


    【解决方案1】:

    使用 Controller TempData(重定向)和 ViewData(对于 ajax)修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 2016-11-03
      • 2016-12-01
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多