Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to create a cross domain SharePoint Modal Dialog using SameOrigin Policy - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2013-10-14

SharePoint Modal Dialog (SP.UI.ModalDialog.showModalDialog(options)) is one of the most commonly used developer features. DocRead and DocSurvey both utilise this “out of the box” modal dialog box to display forms and information to the user.

Recently, when we were working on the DocSurvey application, we came across this challenge (one of the many challenges) of rendering a DocSurvey (enhanced SharePoint Survey) from a different application domain in SharePoint 2013.

For Example: How do you ask a user to respond to a survey that was generated cross-domain / cross-site ? (e.g. the survey is saved in intranet.collaboration.com but is required to be filled in from mysites.collaboration.com).

In SharePoint 2013, if we try to display content from a different domain (within a modal window) using the SP.UI.ModalDialog , the browser will display a warning message and wont display the content as below.

The browser was throwing an error message because the SharePoint has requested the browser to display only the content from the same domain only using the Header (X-FRAME-OPTIONS”, “SAMEORIGIN”). It is because the SP 2013 Request module sets this header in the response header of each request.

Microsoft.SharePoint.ApplicationRuntime.SPRequestModule:

if (!httpContext.Items.Contains(SPRequestModule.AllowFramingFlag) && SPRequestModule.ContextCompatibilityLevel != 14)
{
httpContext.Response.AddHeader("X-FRAME-OPTIONS", "SAMEORIGIN");
}

The code above sets this header if the AllowFramingFlag is not set and the CompatibilityLevel is not 14. 

Solution: 

After a bit of searching, I found the solution here about the Microsoft.SharePoint.WebPart.AllowFraming control for the above issue. To resolve this, simply add this control into your page (or code behind) on the page that we want to display in a cross domain modal dialog.

So this is what it does,

Microsoft.SharePoint.WebPartPages.AllowFraming

if (this.Context != null && !this.Context.Items.Contains(SPRequestModule.AllowFramingFlag)) {

this.Context.Items.Add(SPRequestModule.AllowFramingFlag, "1");
}

It just simply sets the flag so that the Request module will not set the X-FRAME-OPTIONS header.

(Visited 120 times, 1 visits today)

About the author 

Balamurugan Kailasam

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.