Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems reading cookies in Sharepoint with anonymous access

I save a cookie in a sharepoint webpart in 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);

That cookie is always saved successfully. I can see it on the client using firebug. When I try to read that cookie:

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

It DOES work when I am signed in, but it does not if I am not logged in.

Saving always works no matter if I am logged in or not. So where is the error?

like image 267
Ole Albers Avatar asked Nov 10 '11 14:11

Ole Albers


1 Answers

After days of trial and error and testing it seemed to be a caching issue from one (or multiple) of these participants: [Sharepoint, IIS, browser]

Adding

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

solved the problem. I just don't know why caching is different in anonymous access

like image 104
Ole Albers Avatar answered Nov 07 '22 12:11

Ole Albers