ASP.NET Tip: How to Implement P3P HTTP Headers

本文解释了为何在使用iframe时需要实现P3P政策。在特定浏览器配置下(如IE6/7隐私设置为中等),若未实施P3P,则可能导致应用内cookie无法正常工作,进而影响会话管理。文章提供了ASP.NET环境下实现P3P的一个示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


The Problem
Q: Why "make sure to implement P3P if using iframes" ?

 

A: If your application is inside iframe with parent belongs to another domain - cookies will not work for some very common configurations for example IE 6/7 with privacy set to medium. If cookies don't work - session won't work.

 

Therefore session state turns out useless for your application under Internet Explorer. See - Privacy in Internet Explorer 6.

 

This is relevant when domain that hosts iframe is different from parent domain. Because of the fact that this is not very common scenario - only a few familiar with the solution.

 

The Solution
Solution - need to implement P3P header to tell the browser that cookies for your application inside iframe are OK for user privacy.

 

So, ASP.NET implementation may look like the following (global.asax):

 

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    //
    HttpContext.Current.Response.AddHeader("p3p", "CP=\"CAO PSA OUR\"");
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值