Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have farm solution Visual web part, with the following write and read cookies methods

void writeCookie(Guid thisVoteGuid, string pollID)
    HttpCookie pollCookies = new HttpCookie(COOKIE_NAME);
    pollCookies.Value = thisVoteGuid.ToString() + ";" + pollID;
    pollCookies.Expires = DateTime.Now.AddDays(30);

string readCookie()
    //Get Cookie value
    HttpCookie theCookie = Request.Cookies[COOKIE_NAME];
    if (theCookie != null)
       return theCookie.Value;
     return string.Empty;

The read function fails to get the cookie (of-course, since the write method didnt store the cookie at all!), I checked Temporary Internet Files to confirm that no cookie stored

How to read/write cookies in visual webPart-Farm solution?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The code you use looks ok... Does your browser allow you to save cookies? (Since cookies are stored client-side) If you need to be sure that every user uses this, you'll need a server-side solution like viewstate, session, database,... since not every user allows cookies!

share|improve this answer
After two-three tries it worked, I don't know why, but what Im sure about that I didnt change any of the IE options!, anyway I'll accept your post as an answer, Thank you. –  Rami.Shareef Mar 25 '12 at 6:59

i am having similar kind of issue. my requirement is to store cookie in IE using code of sharepoint user control. The problem is, i am able to add and access cookies when i am in debug mode. However, when i deployed my webpart, i am not able to store the cookies.

any thing specific thing need to be done?

appreciate your prompt help. thanks raj

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.