Cookie blocked/not saved in IFRAME in Internet Explorer

前端 未结 22 2089
死守一世寂寞
死守一世寂寞 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: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).

    /// 
    /// 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.
    /// 
    /// 
    /// More info http://www.oreillynet.com/lpt/a/1554
    /// 
    public class P3PAttribute : ActionFilterAttribute
    {
        /// 
        /// On Action Executing add a compact policy "p3p" HTTP header
        /// 
        /// 
        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();
        }
    }
    

提交回复
热议问题