I set a cookie like this in one page:
Request.Cookies["lang"].Value = "en-US";
Request.Cookies["lang"].Expires = DateTime.Now.AddDays(50);
On another page I try and read the cookie:
string lang = Server.HtmlEncode(Request.Cookies["lang"].Value);
The cookie is not null but the value is an empty string. What am I doing wrong?
You should be using
Response.Cookiesto set the cookie, andRequest.Cookiesto read any cookies sent back from the client.The code in your question is setting the cookie in the
Requestobject, not theResponse.