S
Sean M
Guest
I am copying it exactly from the book and there is only 3 lines of code! I have my IE7 privacy setting enabled to allow all cookies. It's not working. Why? I can't get it to work locally or on my site. The page for this project on my site is http://www.seansbagoftricks.com/PracticeApps/CreateCookie/CreateCookie.aspx ...it's all messed up right now (broken links and a description for another page) but right now I'm just trying to get the cookie thing to work.
I don't know if this will help but my site is 2.0 and the book I'm copying from is 3.5.
Can you help me?
1
2 // to save the cookie I am using
3 protected void btnCookie_Click(object sender, EventArgs e)
4 {
5 HttpCookie myCookie = new HttpCookie("UserName", txtCookie.Text);
6 myCookie.Expires = DateTime.Now.AddDays(7);
7 Response.Cookies.Add(myCookie);
8 Response.Redirect("ShowCookie.aspx");
9 }
10
11 // to retrieve the cookie I am using
12 protected void Page_Load(object sender, EventArgs e)
13 {
14 if (!IsPostBack)
15 if (!(Request.Cookies["myCookie"] == null))
16 lblCookieText.Text = "When the cookie that you saved was opened up it read:" + Request.Cookies["myCookie"].Value;
17 else
18 lblCookieText.Text = "You haven't created a cookie yet.";
19 }
ANSWER:
I created UserName and searched for myCookie. The cookie had been created, I was just search for a different name.
Question will be deleted in a few hours. I would delete it now but someone might be giving a long answer and I don't want them to not be able to post.
I don't know if this will help but my site is 2.0 and the book I'm copying from is 3.5.
Can you help me?
1
2 // to save the cookie I am using
3 protected void btnCookie_Click(object sender, EventArgs e)
4 {
5 HttpCookie myCookie = new HttpCookie("UserName", txtCookie.Text);
6 myCookie.Expires = DateTime.Now.AddDays(7);
7 Response.Cookies.Add(myCookie);
8 Response.Redirect("ShowCookie.aspx");
9 }
10
11 // to retrieve the cookie I am using
12 protected void Page_Load(object sender, EventArgs e)
13 {
14 if (!IsPostBack)
15 if (!(Request.Cookies["myCookie"] == null))
16 lblCookieText.Text = "When the cookie that you saved was opened up it read:" + Request.Cookies["myCookie"].Value;
17 else
18 lblCookieText.Text = "You haven't created a cookie yet.";
19 }
ANSWER:
I created UserName and searched for myCookie. The cookie had been created, I was just search for a different name.
Question will be deleted in a few hours. I would delete it now but someone might be giving a long answer and I don't want them to not be able to post.