SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.