5

I'm currently returning a cookie from a web service with code like this:

HttpResponse response = ...; var cookie = new HttpCookie(cookieName) { Value = cookieValue, Expires = expiresDate, HttpOnly = true, Path = "/", Secure = true, }; response.Cookies.Add(cookie); 

This results in the automatic addition of a no-cache directive in my Cache-Control header:

Cache-Control: public, no-cache="Set-Cookie", must-revalidate, max-age=60

My client happens to handle this directive by straight up not caching the response at all. If I manually remove the no-cache directive before it hits the client, caching works great.

How can I prevent .NET from automatically adding this directive to responses containing cookies?

1 Answer 1

7

HttpResponse determines whether it should add this directive based on whether the Cookies collection is non-empty. Therefore, if you add the header manually you can hide its presence from .NET:

response.AddHeader("Set-Cookie", String.Format( "{0}={1}; expires={2}; path=/; secure; HttpOnly", cookieName, cookieValue, expiresDate.ToString("R"))); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.