當網頁 A (例如 https://main.com) 嵌入 `
SessionId根本原因:IE 6/7/8 預設啟用 P3P (Platform for Privacy Preferences) 政策,封鎖無隱私聲明的第三方 Cookie。Session 依賴 Cookie 儲存 SessionId,Cookie 被封鎖 → 每次請求無 SessionId → 伺服器建立新 Session → 使用者無法維持登入狀態。
在 iframe 內嵌頁面 (或其母版頁/基底頁面) 的 最早期階段 送出 P3P 標頭,宣告隱私政策,讓 IE 允許 Cookie。
// Global.asax - Application_BeginRequest (最早攔截點)
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("P3P",
"CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
}
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
Response.AddHeader("P3P",
"CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
base.OnActionExecuting(filterContext);
}
}
// Startup.cs - Configure 方法中
app.Use(async (context, next) =>
{
context.Response.Headers["P3P"] =
"CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"";
await next();
});
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="P3P" value='CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"' />
</customHeaders>
</httpProtocol>
</system.webServer>
CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
| 代碼 | 全稱 | 中文說明 |
|---|---|---|
| IDC | Independent Decision Making | 獨立決策 - 不與他方共享資料 |
| DSP | Dispute Resolution | 爭議解決機制 |
| COR | Correction | 資料更正權利 |
| ADM | Administrative | 行政用途 |
| DEVi | Development (Identifiable) | 網站開發改善 (可識別個人) |
| TAIi | Tailoring (Identifiable) | 個性化服務 (可識別個人) |
| PSA | Pseudo-Analysis | 偽名分析 |
| PSD | Pseudo-Decision Making | 偽名決策 |
| IVAi | Individual Analysis (Identifiable) | 個人分析 (可識別) |
| IVDi | Individual Decision Making (Identifiable) | 個人決策 (可識別) |
| CONi | Contact (Identifiable) | 聯絡用途 (可識別) |
| HIS | Historical | 歷史記錄保存 |
| OUR | Ours | 自身及關聯機構共用 |
| IND | Individual | 個人化內容 |
| CNT | Content | 內容提供 |
注意:此政策字串僅為常用範例,實際部署應依據真實隱私政策編寫,並對應 /w3c/p3p.xml 完整政策檔案。
SameSite=None; Secure (需 HTTPS) 明確允許跨域攜帶services.ConfigureApplicationCookie(options =>
{
options.Cookie.SameSite = SameSiteMode.None;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always; // 必須 HTTPS
});
SameSite=None; Secure (現代瀏覽器)P3P 標頭是解決 IE7/8 iframe 跨域 Session 失效的經典方案。雖然現代瀏覽器已棄用 P3P 轉向 SameSite 機制,但在維護舊系統或特定企業環境 (強制 IE 相容模式) 時,此方案仍具實戰價值。建議雙軌並行:舊版 IE 用 P3P,現代瀏覽器用 SameSite=None,並在架構層面評估遷移至同域或 OAuth/OIDC 單一登入方案。