Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Implement Cookie in Sahrepoint

$
0
0

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);


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>