I'm trying to remove specific Set-Cookie header from HttpResponseHeaders in OnActionExecuted method of ActionFilter.
I'm having few issues with that:
- I cannot see the way of enumerate headers. The collection is always empty, even if I see headers in debugger.
- Because I cannot enumerate, I cannot remove specific header. I can only remove all headers with the same key, but
Set-Cookiecan have multiple entries.
Currently I'm removing all cookies, but this is not what I want.
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { HttpResponseHeaders headers = actionExecutedContext.Response.Headers; IEnumerable<string> values; if (headers.TryGetValues("Set-Cookie", out values)) { actionExecutedContext.Response.Headers.Remove("Set-Cookie"); } base.OnActionExecuted(actionExecutedContext); }
OnActionExecutingHttpContext.Current.Items.Add("RemoveAuthCookieKey", true);. And then in Global.asax inApplication_EndRequestif key existsthis.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);