Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Creating cookies with HttpCookie vs. Response.Cookies

Creating cookies with HttpCookie vs. Response.Cookies

Scheduled Pinned Locked Moved ASP.NET
sysadminvisual-studiohelpquestionworkspace
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goodideadave
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups