joe_pool_is Posted August 19, 2005 Posted August 19, 2005 Can anyone see why my bigCookie, "cookieMonster", is not being set?public void Page_Load (object sender, System.EventArgs e) { string strUserId = "jdoe"; string strName = "John Doe"; string strDate = DateTime.Now.ToString(); HttpCookie bigCookie = Request.Cookies["cookieMonster"]; if (IsPostBack) { // Page Loads for first time Label1.Text = "Is Postback"; } else { // User Clicked a button Label1.Text = "Is Not Postback"; } if (bigCookie == null) { Label2.Text = "bigCookie = null"; bigCookie = new HttpCookie("cookieMonster"); bigCookie.Values.Add("userId", strUserId); bigCookie.Values.Add("name", strName); bigCookie.Values.Add("lastVisit", strDate); bigCookie.Expires = DateTime.Now.AddDays(365); bigCookie.Path = Server.MapPath("/"); Response.Cookies.Add(bigCookie); } else if (bigCookie["userId"].ToString() == "") { Label2.Text = "bigCookie = (blank)"; bigCookie = new HttpCookie("cookieMonster"); bigCookie.Values.Add("userId", strUserId); bigCookie.Values.Add("name", strName); bigCookie.Values.Add("lastVisit", strDate); bigCookie.Expires = DateTime.Now.AddDays(365); bigCookie.Path = Server.MapPath("/"); Response.Cookies.Add(bigCookie); } else { Label2.Text = "bigCookie value set"; strUserId = bigCookie["userId"].ToString(); strName = bigCookie["name"].ToString(); strDate = bigCookie["lastVisit"].ToString(); } } Label2.Text is always "bigCookie = null" whether IsPostBack is true or not, but I don't know how I should rewrite the code to make the changes. Am I writing this cookie the wrong way? Am I reading it in the wrong way? Any suggestions??? Quote Avoid Sears Home Improvement
joe_pool_is Posted August 19, 2005 Author Posted August 19, 2005 I replacedResponse.Cookies.Add(bigCookie);withResponse.AppendCookie(bigCookie);but my page still loads up with Label2.Text = "bigCookie = null". Any other ideas? Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.