【问题标题】:How to remove cookie in Hosted environment, which i works in local environment?如何在托管环境中删除 cookie,我在本地环境中工作?
【发布时间】:2014-03-31 17:08:54
【问题描述】:

我正在使用带有 AngularJS 作为前端的 Web api,我在本地环境中开发了一个应用程序,并且在本地一切正常。但是今天我不得不在服务器上托管我的应用程序,我突然无法删除我可以在本地执行的 cookie:

public virtual HttpResponseMessage UnAuthenticate()
{
    if (HttpContext.Current.Request.Cookies["sessionId"] != null)
    {
        HttpCookie cookie = HttpContext.Current.Request.Cookies["sessionId"];
        cookie.Expires = DateTime.Now.AddDays(-1);
        HttpContext.Current.Response.Cookies.Add(cookie);
    }
    HttpRuntime.Cache.Remove("cacheToken");
    return null;
}

我做错了什么?

更新

它在 IE 中有效,但在 Chrome 中失败。

【问题讨论】:

标签: c# asp.net .net cookies asp.net-web-api


【解决方案1】:

试试这个

public virtual HttpResponseMessage UnAuthenticate()
{
    HttpCookie cookie = HttpContext.Current.Response.Cookies["sessionId"];
    if (cookie != null)
    {
        cookie.Expires = DateTime.Now.AddDays(-1);
    }
    return null;
}

【讨论】:

    猜你喜欢
    • 2020-03-21
    • 1970-01-01
    • 2021-12-08
    • 2020-01-09
    • 2011-10-10
    • 2022-06-11
    • 2014-01-25
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多