Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing cookies in ASP.NET - works in Firefox/Safari but not IE

Status
Not open for further replies.

tcstom

Programmer
Aug 22, 2003
235
0
0
GB
I'm using the following code to write a cookie...

Code:
HttpCookie objCookie = new HttpCookie("TCS_DATA_REQUEST");
objCookie.Expires = DateTime.Now.AddYears(1);
objCookie.Values.Add("TCS_DATA_PROVIDED", "yes");
Response.Cookies.Add(objCookie);

...and then as part of a subsequent page load I'm using this code to retrieve the cookie and check it...

Code:
HttpCookie objCookie = Request.Cookies["TCS_DATA_REQUEST"];
if (objCookie != null ? objCookie.Values["TCS_DATA_PROVIDED"] == "yes" : false)
{
	// Never gets here if using IE
}

This works fine in Firefox but using the same application in IE always fails to retrieve the Cookie (objCookie is null). Is there something I'm not doing, or is this just another part of Internet Explorer's personal vendetta against me?
 
I should have mentioned that the page writing the cookie is in an iframe and I've now discovered that IE by default blocks such cookies as untrustworthy. Why can't Microsoft just follow the rules? If anyone knows a work-around I'd be enormously grateful. The iframe here is necessary.
 
Who would have thought it! It turns out that the solution is to supply a 'compact privacy policy' with your page. So, for every page that will be writing a cookie from an iFrame, include the following line of code:

Code:
HttpContext.Current.Response.AddHeader("p3p", "CP=\""IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""")

I don't know how it works but it works! Thanks to Mr Gath Adams for this one -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top