cookie not working in internet explorer

Posted on 2011-10-11
Medium Priority
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
  • 3
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36953743
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
ID: 36953959
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

ID: 36954108
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

edaj6 earned 0 total points
ID: 36954208
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

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

850 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