Hi,
I have requirement of implementin cookie in my web part.I have used the following code.
HttpCookie objPollingCookie = HttpContext.Current.Response.Cookies[strListURL + "|" + iListItemID + "|" + SPContext.Current.Web.CurrentUser.ID]; if ((objPollingCookie != null) && (objPollingCookie.Value != null)) { //HttpCookie objPollingCookie = this.Page.Response.Cookies[strListURL + "|" + iListItemID + "|" + SPContext.Current.Web.CurrentUser.ID]; Utils objDecrypt=new Utils(); string strVoteStatus = objDecrypt.DecryptString(objPollingCookie.Value); if (strVoteStatus == "Yes") { return true; } else { return false; }
}
The cookie never returns false cookie is present their with some default values with date as 0001-01-01 ,ie why I have addded the conditon for cookie.value==null. The cookie I am writing are also not geting saved .Is there anything I am missing for implementing the cookie in sharepoint.COde for writing cookie is given below
HttpCookie objPollingCookie = new HttpCookie(strListURL+"|"+iListItemID+"|"+SPContext.Current.Web.CurrentUser.ID); objPollingCookie.Value = objEncrypt.EncryptData("Yes"); objPollingCookie.Expires = DateTime.Now.AddMonths(1); HttpContext.Current.Response.Cookies.Add(objPollingCookie);