Problems reading cookies on Sharepoint with anonymous access

I save the cookie in the sharepoint web part this way:

System.Web.HttpCookie cookie = new System.Web.HttpCookie(_cookieApplicationId); cookie[_cookieName] = value; cookie.Expires = DateTime.Now.AddMonths(1); HttpContext.Current.Response.SetCookie(cookie); 

This cookie is always saved successfully. I see this on the client using firebug. When I try to read this cookie:

 System.Web.HttpCookie cookie = HttpContext.Current.Request.Cookies[_cookieApplicationId]; return cookie[_cookieName]; 

It works when logging in, but this is not the case if I have not logged in.

Saving always works whether I am logged in or not. So where is the mistake?

+7
source share
1 answer

After several days of trial and error and testing, this seemed to be a caching problem from one (or several) participants: [Sharepoint, IIS, browser]

Adding

 HttpContext.Current.Response.Cache.SetNoServerCaching(); HttpContext.Current.Response.Cache.SetNoStore(); 

solved a problem. I just don’t know why caching is different from anonymous access

+3
source

All Articles