How can I remove 'no-cache = "Set-Cookie" when I add a cookie to HttpResponse?

I am 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 causes the directive to be automatically added without a cache to my Cache-Control header:

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

My client handles this directive simply by not caching the response. If I manually delete the directive without a cache before it hits the client, caching works fine.

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

+2
source share
1 answer

HttpResponse determines whether to add this directive depending on whether the Cookies collection is non-empty. Therefore, if you add the header manually, you can hide your presence from .NET:

 response.AddHeader("Set-Cookie", String.Format( "{0}={1}; expires={2}; path=/; secure; HttpOnly", cookieName, cookieValue, expiresDate.ToString("R"))); 
+6
source

Source: https://habr.com/ru/post/945836/


All Articles