cookie not working in internet explorer

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"];
            else
                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";
            Response.Cookies.Add(aCookie);
        }

Open in new window

edaj6Asked:
Who is Participating?
 
edaj6Author Commented:
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.
0
 
Michel PlungjanIT ExpertCommented:
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);
Response.Cookies.Add(aCookie);
0
 
Anurag ThakurTechnical ManagerCommented:
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."
0
 
edaj6Author Commented:
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.
0
 
edaj6Author Commented:
Didn't solve problem, but I found a work around.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.