I have the following code that sets a cookie:
string locale = ((DropDownList)this.LoginUser.FindControl('locale')).SelectedValue; HttpCookie cookie = new HttpCookie('localization',locale); cookie.Expires= DateTime.Now.AddYears(1); Response.Cookies.Set(cookie);
However, when I try to read the cookie, the Value is Null. The cookie exists. I never get past the following if check:
if (Request.Cookies['localization'] != null && !string.IsNullOrEmpty(Request.Cookies['localization'].Value))
Help?
The check is done after a post back? If so you should read the cookie from the Request collection instead.
The cookies are persisted to the browser by adding them to Response.Cookies and are read back from Request.Cookies.
The cookies added to Response can be read only if the page is on the same request.