Cookie blocked/not saved in IFRAME in Internet Explorer

前端 未结 22 2119
死守一世寂寞
死守一世寂寞 2020-11-22 00:53

I have two websites, let\'s say they\'re example.com and anotherexample.net. On anotherexample.net/page.html, I have an IFRAME S

相关标签:
22条回答
  • 2020-11-22 01:09

    If you own the domain that needs to be embedded, then you could, before calling the page that includes the IFrame, redirect to that domain, which will create the cookie and redirect back, as explained here: http://www.mendoweb.be/blog/internet-explorer-safari-third-party-cookie-problem/

    This will work for Internet Explorer but for Safari as well (because Safari also blocks the third-party cookies).

    0 讨论(0)
  • 2020-11-22 01:10

    One possible thing to do is to add the domain to allowed sites in tools -> internet options -> privacy -> sites: somedomain.com -> allow -> OK.

    0 讨论(0)
  • 2020-11-22 01:12

    I had this issue as well, thought I'd post the code that I used in my MVC2 project. Be careful when in the page life cycle you add in the header or you'll get an HttpException "Server cannot append header after HTTP headers have been sent." I used a custom ActionFilterAttribute on the OnActionExecuting method (called before the action is executed).

    /// <summary>
    /// Privacy Preferences Project (P3P) serve a compact policy (a "p3p" HTTP header) for all requests
    /// P3P provides a standard way for Web sites to communicate about their practices around the collection, 
    /// use, and distribution of personal information. It's a machine-readable privacy policy that can be 
    /// automatically fetched and viewed by users, and it can be tailored to fit your company's specific policies.
    /// </summary>
    /// <remarks>
    /// More info http://www.oreillynet.com/lpt/a/1554
    /// </remarks>
    public class P3PAttribute : ActionFilterAttribute
    {
        /// <summary>
        /// On Action Executing add a compact policy "p3p" HTTP header
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpContext.Current.Response.AddHeader("p3p","CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
    
            base.OnActionExecuting(filterContext);
        }
    }
    

    Example use:

    [P3P]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome!";
    
            return View();
        }
    
        public ActionResult About()
        {
            return View();
        }
    }
    
    0 讨论(0)
  • 2020-11-22 01:12

    You can also combine the p3p.xml and policy.xml files as such:

    /home/ubuntu/sites/shared/w3c/p3p.xml

    <META xmlns="http://www.w3.org/2002/01/P3Pv1">
      <POLICY-REFERENCES>
        <POLICY-REF about="#policy1">
          <INCLUDE>/</INCLUDE>
          <COOKIE-INCLUDE/>
        </POLICY-REF>
      </POLICY-REFERENCES>
      <POLICIES>
        <POLICY discuri="" name="policy1">
          <ENTITY>
            <DATA-GROUP>
              <DATA ref="#business.name"></DATA> 
              <DATA ref="#business.contact-info.online.email"></DATA> 
            </DATA-GROUP>
          </ENTITY>
          <ACCESS>
            <nonident/>
          </ACCESS>
          <!-- if the site has a dispute resolution procedure that it follows, a DISPUTES-GROUP should be included here -->
          <STATEMENT>
            <PURPOSE>
              <current/>
              <admin/>
              <develop/>
            </PURPOSE>
            <RECIPIENT>
              <ours/>
            </RECIPIENT>
            <RETENTION>
              <indefinitely/>
            </RETENTION>
            <DATA-GROUP>
              <DATA ref="#dynamic.clickstream"/>
              <DATA ref="#dynamic.http"/>
            </DATA-GROUP>
          </STATEMENT>
        </POLICY>
      </POLICIES>
    </META>
    

    I found the easiest way to add a header is proxy through Apache and use mod_headers, as such:

    <VirtualHost *:80>
      ServerName mydomain.com
    
      DocumentRoot /home/ubuntu/sites/shared/w3c/
    
      ProxyRequests off
      ProxyPass /w3c/ !
      ProxyPass / http://127.0.0.1:8080/
      ProxyPassReverse / http://127.0.0.1:8080/
      ProxyPreserveHost on
    
      Header add p3p 'P3P:policyref="/w3c/p3p.xml", CP="NID DSP ALL COR"'
    </VirtualHost>
    

    So we proxy all requests except those to /w3c/p3p.xml to our application server.

    You can test it all with the W3C validator

    0 讨论(0)
  • 2020-11-22 01:12

    For anyone trying to get the P3P Compact Policy working with static content:

    It is only possible if you are able to send custom server-side response headers with the static content.

    For a more detailed explanation see my answer here: Set P3P code in HTML

    0 讨论(0)
  • 2020-11-22 01:14

    I was able to make the evil eye go away by simply adding this small header to the site in the IFrame (PHP solution):

    header('P3P: CP="NOI ADM DEV COM NAV OUR STP"');
    

    Remember to press ctrl+F5 to reload your site or Explorer may still show the evil eye, despite the fact that it's working fine. This is probably the main reason why I had so many problems getting it to work.

    No policy file was neccesary at all.

    Edit: I found a nice blog entry that explains the problem with cookies in IFrames. It also has a quick fix in C# code: Frames, ASPX Pages and Rejected Cookies

    0 讨论(0)
提交回复
热议问题