cookie not working in internet explorer

Posted on 2011-10-11
Last Modified: 2013-12-08
I am trying to add a cookie to an intranet page. It works fine on local host when testing, both ie8 and firefox. When I publish to iis7 it only works in firefox.

I am not getting any errors in ie8, the cookie is just not saved. Security is set to local intranet/low.

protected void lnkLoadCookie_Click(object sender, EventArgs e)
            HttpCookie MyCookie = Request.Cookies["testcookie"];

            if (MyCookie != null)
                lnkCookie.Text = MyCookie.Values["test"];
                lnkCookie.Text = "no cookie";


        protected void lnkSaveCookie_Click(object sender, EventArgs e)
            HttpCookie aCookie = new HttpCookie("testcookie");
            aCookie.Values["test"] = "testvalue";
            aCookie.Expires = DateTime.Now.AddYears(1);

            lnkCookie.Text = "cookie saved";

Open in new window

Question by:edaj6
    LVL 75

    Expert Comment

    by:Michel Plungjan
    I am not a C# person, but try this - you set only one value so use .Value

    HttpCookie aCookie = new HttpCookie("testcookie");
    aCookie.Value= "testvalue";
    aCookie.Path= "/";
    aCookie.Expires = DateTime.Now.AddYears(1);
    LVL 26

    Expert Comment

    by:Anurag Thakur
    on dev it always works fine
    but can you try the following (copied from somewhere)

    "I have some suggestions to add to those that Debbie made.   IE8 has an option for InPrivate Browsing.  If you are browsing in this mode no cookies or history is saved.  The easiest way to see if you are in this mode is there will be a blue bar at the beginning of the address bar that says “InPrivate”.  This is activated by going to the “Safety” button on the Menu Bar and selecting InPrivate Browsing.  When you close and re-launch IE8 you should be returned to normal browsing.  If this hasn’t been turned on then the security settings in IE8 have been set to NOT allow cookies or you could be running third party internet security software program that is blocking cookies.  We can check the IE8 security settings by going to the “Tools” button on the Menu Bar and clicking Internet Options.  Click on the Security tab and click on the icon for Internet.   The slide adjuster just below Security Level for This Zone by default is set to Medium-High.  This setting does allow cookies so try setting to this level.   Now click on the Privacy tab.  The slide adjuster below Select a Setting for the Internet Zone is set to Medium by default.  This setting will allow the type of cookies that you are referring to so if it is not set to Medium set it there.  Click Apply and click OK.  Now close and restart IE8 and see if you can set the passwords you are referring to.  Close IE8 and reboot.  Did the cookies save?  If not could you let us know if you are using an Internet Security software package or Antivirus program?  This will allow us to assist you with further troubleshooting."

    Author Comment

    thanks for comments.

    mplungjan: I use .values because I want to add more values later. I have tested with .value and .path - no difference

    ragi0017: I have tested what you suggest. I am not in inPrivate mode, the zone is local intranet and security is set to low, allowing all.

    On IE8 I can browse to http://localhost and everything works, when published to intranet it doesn't work. Same browser, same zone, same settings. I suspect it must be something with IIS7 on intranet being different from my localhost.

    Accepted Solution

    I am using Symantec Endpoint Protection. Tried to disable no difference.

    I just tried making a new application on the webserver and that solved it.

    Still I have no idea why it's working in one app and not another. Application pool has same settings and cant find any differences in application. Maybe a server reboot will solve it but can't do that right now.

    Author Closing Comment

    Didn't solve problem, but I found a work around.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Now-a-days, indirectly, postal services have been replaced by email services. Yes, whenever we hear the word "email" a lot of people only think of gmail. Some people still think that email and gmail are one and the same thing :-). Let's see some …
    #Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
    Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now