A
Ash
Hi
I'm creating a cookie on my site, and adding values to it, namely a userid
and a groupid:
Function1:
oCookie.Values["groupid"] = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);
Function2:
oCookie.Values["userid"] = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);
where oCookie is created like this:
HttpCookie oCookie = HttpContext.Current.Request.Cookies[CookieName];
if (oCookie == null)
{
oCookie = new HttpCookie(CookieName);
HttpContext.Current.Response.Cookies.Add(oCookie);
}
return oCookie;
My problem is this:
When I add the groupID, and then call Cookies.Set, a new Cookie with the
same name is added to the Cookies Collection, instead of just setting the
groupid value. ie, it creates two cookies, both with the groupid key and
value. If I omit the Cookies.Set, the cookie is created only once, and
everything is fine......
except, when I do this with the userID, if I don't call Cookies.Set, the
userID is not set to the cookie. If I do, the value/name pair is added to
the existing cookie, like it should be.
So, for clarity, these are the three scenarios:
1. Add groupID, call Cookies.Set, Add userID call Cookies.Set = two Cookies
created, both with the correct name value pairs.
2. Add groupID, DON'T call Cookies.Set, Add userID call Cookies.Set = one
Cookie created, both with the correct name value pairs. (DESIRED RESULT)
3. Add groupID, call Cookies.Set, Add userID DON'T call Cookies.Set = one
Cookie created, userID name/value pair not created.
How much sense does this make?!?
The setting of the groupid takes place before the userid, at different
points in the application. oCookie always exists when the setting of these
values take place. The cookie's a session cookie ie. doesn't persist.
Any insight would be greatly appreciated.
Ash
I'm creating a cookie on my site, and adding values to it, namely a userid
and a groupid:
Function1:
oCookie.Values["groupid"] = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);
Function2:
oCookie.Values["userid"] = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);
where oCookie is created like this:
HttpCookie oCookie = HttpContext.Current.Request.Cookies[CookieName];
if (oCookie == null)
{
oCookie = new HttpCookie(CookieName);
HttpContext.Current.Response.Cookies.Add(oCookie);
}
return oCookie;
My problem is this:
When I add the groupID, and then call Cookies.Set, a new Cookie with the
same name is added to the Cookies Collection, instead of just setting the
groupid value. ie, it creates two cookies, both with the groupid key and
value. If I omit the Cookies.Set, the cookie is created only once, and
everything is fine......
except, when I do this with the userID, if I don't call Cookies.Set, the
userID is not set to the cookie. If I do, the value/name pair is added to
the existing cookie, like it should be.
So, for clarity, these are the three scenarios:
1. Add groupID, call Cookies.Set, Add userID call Cookies.Set = two Cookies
created, both with the correct name value pairs.
2. Add groupID, DON'T call Cookies.Set, Add userID call Cookies.Set = one
Cookie created, both with the correct name value pairs. (DESIRED RESULT)
3. Add groupID, call Cookies.Set, Add userID DON'T call Cookies.Set = one
Cookie created, userID name/value pair not created.
How much sense does this make?!?
The setting of the groupid takes place before the userid, at different
points in the application. oCookie always exists when the setting of these
values take place. The cookie's a session cookie ie. doesn't persist.
Any insight would be greatly appreciated.
Ash