在之前的SharePoint站點iframe引用中,我們遇到過下面的問題,就是其它系統或者不通環境的SharePoint站點,引用SharePoint頁面會報錯“此內容不能顯示在一個框架中”,之前我們采取了解決方案的辦法。
今天,無意中翻看msdn,發現了更加簡便的方法,分享給大家。
原理介紹
在大部分情況下,如果網頁在響應中發送 X-Frame-Options HTTP 頭,則該網頁將無法在框架中顯示。默認情況下,SharePoint 網頁包含 X-Frame-Options 頭。如果使用應用程序 Web 承載的 SharePoint 網頁,您可能會遇到以下錯誤(如上圖所示):"此內容無法在框架中顯示"。
This content cannot be displayed in a frame
To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame.
What you can try:
Open this content in a new window
請記住,當網頁在框架中顯示時,特定方案易受"點擊劫持"攻擊。請仔細評估您的應用程序部件方案,以確保不存在點擊劫持攻擊風險。
如果在應用程序 Web 中承載的頁面不易受點擊劫持攻擊,則您可以使用 AllowFraming Web 部件抑制頁面響應中的 X-Frame-Options 頭。下面的代碼示例展示如何在 SharePoint 頁面中使用 AllowFraming Web 部件。
<webpartpages:allowframing id="AllowFraming1" runat="server"/>
解決方法
使用SharePoint Designer打開該頁面(特別的,修改的是要被iframe方式引用的頁面)的頁面布局,加入如下圖代碼:
特別要說的是,WebPartId會自動生成,不需要我們手動添加;
再次打開頁面,發現iframe的頁面顯示正常了,不再報錯,如下圖:
參考鏈接
http://www.cnblogs.com/jianyus/p/3385514.html
http://msdn.microsoft.com/ZH-CN/library/office/fp179921(v=office.15).aspx