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?
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
链接地址: http://www.djcxy.com/p/9914.html