|
 |
aspx_beginners thread: cookies
Message #1 by "Dan McKinnon" <mddonna@q...> on Tue, 28 May 2002 01:45:50
|
|
Hi -
I have questions about creating cookies with .net. The example
in "Beginning ASP.NET Using VB.NET" is confusing to me because it seems
like it names the cookie two times.
Their example is:
Public Sub Click(ByVal Sender As Object, e As System.EventArgs)
Dim MyCookie As New HttpCookie("Background")
MyCookie.Value = MyDropDownList.SelectedItem.Text
Response.Cookies.Add(MyCookie)
End Sub
The page that uses the cookie uses this line:
<body bgcolor="<%=Request.Cookies("Background").Value%>">
Doesn't it seem like this cookie has both the names MyCookie and
Background? There is no mention of MyCookie when retrieving the cookie in
the second page.
And what if I want to have several keys in one cookie?
In ASP 3.0, according to "Beginning ASP 3.0" by Wrox, this is the way to
create cookies:
Response.Cookies("cookie_name") = value
and to retrieve them:
Request.Cookies("cookie_name")[("key")].attributes
What I want to do is create and retrieve several keys, but just put one
cookie on the users machine.
Any help would be appreciated.
Dan
Message #2 by "Minh T. Nguyen" <nguyentriminh@y...> on Mon, 27 May 2002 19:30:33 -0700
|
|
Dan,
The name of your variable ("MyCookie") has nothing to do with
the actual name of the cookie that is being stored on the user's
machine. It's just like the DataSet. Your variable instance "MyDataSet"
has nothing to do with the name of the table that comes from SQL server
or that you give using the myDataAdapter.Fill method.
In your example, MyCookie was only used to have a variable, you
can easily add a cookie in one step without a variable:
Response.Cookies.Add(new HttpCookie("UserName", "Dan"));
In order to create a retrieve multiple name/value pairs in one
cookie, just do:
Response.Cookies.Add(new HttpCookie("UserName", "Dan"));
Response.Cookies.Add(new HttpCookie("Occupation",
"Programmer"));
Response.Cookies.Add(new HttpCookie("Sex", "Male"));
...
and retrieve them with
Request.Cookies("UserName").Value
Request.Cookies("Occupation").Value
Request.Cookies("Sex").Value
Hope this helps,
Minh.
-----Original Message-----
From: Dan McKinnon [mailto:mddonna@q...]
Sent: Tuesday, May 28, 2002 1:46 AM
To: aspx_beginners
Subject: [aspx_beginners] cookies
Hi -
I have questions about creating cookies with .net. The example
in "Beginning ASP.NET Using VB.NET" is confusing to me because it seems
like it names the cookie two times.
Their example is:
Public Sub Click(ByVal Sender As Object, e As System.EventArgs)
Dim MyCookie As New HttpCookie("Background")
MyCookie.Value = MyDropDownList.SelectedItem.Text
Response.Cookies.Add(MyCookie)
End Sub
The page that uses the cookie uses this line:
<body bgcolor="<%=Request.Cookies("Background").Value%>">
Doesn't it seem like this cookie has both the names MyCookie and
Background? There is no mention of MyCookie when retrieving the cookie
in
the second page.
And what if I want to have several keys in one cookie?
In ASP 3.0, according to "Beginning ASP 3.0" by Wrox, this is the way to
create cookies:
Response.Cookies("cookie_name") = value
and to retrieve them:
Request.Cookies("cookie_name")[("key")].attributes
What I want to do is create and retrieve several keys, but just put one
cookie on the users machine.
Any help would be appreciated.
Dan
Message #3 by "Dan McKinnon" <mddonna@q...> on Tue, 28 May 2002 11:49:41
|
|
OK, Minh, thanks. This helps quite a bit. Regarding the different
name/value pairs in your example --
Response.Cookies.Add(new HttpCookie("UserName", "Dan"));
Response.Cookies.Add(new HttpCookie("Occupation",
"Programmer"));
Response.Cookies.Add(new HttpCookie("Sex", "Male"));
-- will they will all be stored in one cookie (text file) on the user's
machine?
Dan
Message #4 by "Minh T. Nguyen" <nguyentriminh@y...> on Tue, 28 May 2002 08:22:42 -0700
|
|
Dan,
I don't know. I think it'll be stored in one cookie. As far as I
know a cookie will be stored for each domain. You can always look at the
Temporary Internet Files, I guess.
Minh.
-----Original Message-----
From: Dan McKinnon [mailto:mddonna@q...]
Sent: Tuesday, May 28, 2002 11:50 AM
To: aspx_beginners
Subject: [aspx_beginners] RE: cookies
OK, Minh, thanks. This helps quite a bit. Regarding the different
name/value pairs in your example --
Response.Cookies.Add(new HttpCookie("UserName", "Dan"));
Response.Cookies.Add(new HttpCookie("Occupation",
"Programmer"));
Response.Cookies.Add(new HttpCookie("Sex", "Male"));
-- will they will all be stored in one cookie (text file) on the user's
machine?
Dan
|
|
 |