|
 |
aspx thread: Use of an HTTPCookie...
Message #1 by "Al LeMay" <alemay@d...> on Sat, 15 Dec 2001 14:49:57 -0800
|
|
This is a multi-part message in MIME format.
------_=_NextPart_001_01C185BA.D1F0614C
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
All
I am trying to use an HTTPCookie but am unable to actual get at the
values I stick into the cookie.
Code to insert a value:
MyCookie.Values.Add("KeyName",myRow[myColumn].ToString();
Code to retrieve value:
MyCookieCollection =3D Response.Cookies;
Cookienames =3D MyCookieCollection.AllKeys;
For(int x =3D 0; x < cookienames.Length; x++)
{
MyCookie =3D Cookienames[x];
Cookiekeys =3D MyCookie.Values.AllKeys;
For(int y =3D 0; y < cookiekeys.Length; y++)
{
Label1.Text =3D cookiekeys[y];
}
}
I can only seem to get down deep enough to the cookie keys, and never
reach the actual values that the keys have.
Does anybody have a code sample that would help me?
Thanks.
Al
Message #2 by "Mitch Denny" <mitch.denny@w...> on Mon, 17 Dec 2001 13:17:27 +1100
|
|
Al,
The code that you listed wouldn't actually compile
because of a few gramatical errors. But here is the
code I would use to insert a cookie into the response
stream going back to the browser:
// Declare locals.
HttpCookie newCookie = null;
// Construct a new cookie.
newCookie = new HttpCookie("MyCookie", "Some Value");
// Insert the cookie into the response stream.
this.Response.Cookies.Add(newCookie);
Now, it is also quite simple to enumerate over the
cookies that are sent to you.
string currentCookieName = null;
string currentCookieValue = null;
foreach (HttpCookie cookie in this.Response.Cookies) {
// Insert code here to act on each cookie.
currentCookieName = cookie.Name;
currentCookieValue = cookie.Value;
}
You could try an bind it to a DataGrid, but unfortunately
the HttpCookieCollection class doesn't have a HasKeys
member, so the automatic binding fails. You can bind on
the "AllKeys" string array however as a quick and dirty.
Hope this helps.
----------------------------------------
- Mitch Denny
- http://www.warbyte.com
- mitch.denny@w...
- +61 (414) 610-141
-
-----Original Message-----
From: Al LeMay [mailto:alemay@d...]
Sent: Sunday, 16 December 2001 9:50 AM
To: ASP+
Subject: [aspx] Use of an HTTPCookie...
All
I am trying to use an HTTPCookie but am unable to actual get at the
values I stick into the cookie.
Code to insert a value:
MyCookie.Values.Add("KeyName",myRow[myColumn].ToString();
Code to retrieve value:
MyCookieCollection = Response.Cookies;
Cookienames = MyCookieCollection.AllKeys;
For(int x = 0; x < cookienames.Length; x++)
{
MyCookie = Cookienames[x];
Cookiekeys = MyCookie.Values.AllKeys;
For(int y = 0; y < cookiekeys.Length; y++)
{
Label1.Text = cookiekeys[y];
}
}
I can only seem to get down deep enough to the cookie keys, and never
reach the actual values that the keys have.
Does anybody have a code sample that would help me?
Thanks.
Al
|
|
 |