1

I am using Web api with AngularJS as front end, I developed an app in local environment and everything works fine locally. But today I had to host my app on a server, and I suddenly can't remove a cookie which I could do locally:

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;
}

What am I doing wrong?

UPDATE

It works in IE, but it fails in Chrome.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Timsen
  • 4,066
  • 10
  • 59
  • 117

1 Answers1

1

try this

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