Creating cookies with HttpCookie vs. Response.Cookies
ASP.NET
1
Posts
1
Posters
0
Views
1
Watching
-
I have a web site on an internal web server on our enterprise network. When a user who is a member of the admin group on the web server visits the page, cookies are created on the main page and read just fine on the other pages. But if it's a user who is not in that group, no errors are thrown but the cookies don't seem to be written. MSDN gives two techniques for writing cookies. This one does not throw an error, but neither does it create the cookie for all users:
HttpCookie c = new HttpCookie("userinfo"); c.Values\["domainaccount"\] = \_CtaUser.DomainAccount; c.Values\["userid"\] = \_CtaUser.UserID.ToString(); c.Values\["username"\] = \_CtaUser.UserName; c.Values\["rolename"\] = \_CtaUser.RoleName.ToLower(); c.Values\["ctaactiveflag"\] = (\_CtaUser.CTAActiveFlag) ? "1" : "0"; c.Expires = DateTime.Now.AddDays(1d); Response.Cookies.Add(c);
This technique works just fine for all users:
Response.Cookies\["userinfo"\]\["domainaccount"\] = \_CtaUser.DomainAccount; Response.Cookies\["userinfo"\]\["userid"\] = \_CtaUser.UserID.ToString(); Response.Cookies\["userinfo"\]\["username"\] = \_CtaUser.UserName; Response.Cookies\["userinfo"\]\["rolename"\] = \_CtaUser.RoleName.ToLower(); Response.Cookies\["userinfo"\]\["ctaactiveflag"\] = (\_CtaUser.CTAActiveFlag) ? "1" : "0"; Response.Cookies\["userinfo"\].Expires = DateTime.Now.AddDays(1);
As near as I can tell, the browsers for all users are setup identically, and we have tested with IE7 and FF. Can anyone point out what I'm doing wrong? Thanks.
My other signature is witty and insightful.