Issue with loading localhost site in IFrame - asp.net

I have a MVC site that I want to load into Iframe. I have added the X-Frame-Options to AllowAll. When I try to load the site, I can see the html document in developer tools but the IFrame in the Page is blank.
I tried to create a web application on localohost with different port number and where I tried to load the MVC site in Iframe, it didnt work.
I tried to add a html in the same MVC site and loading itself in the html's Iframe (assuming port issue but still it will not load).
Any help will be appreciated.

I recently ran into a similar issue. The X-Frame-Options header did not work for me. I had to use the Content-Security-Policy header. In the web.config file, I set it to frame-src https://my-domain.com like this:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy" value="frame-src {your domain here}" />
</customHeaders>
</httpProtocol>
</system.webServer>

Related

The web host (Apache) will not display a web page from an IIS server

The iframe is being served by Apache (InMotionHosting) and the requested page is from an IIS Server (WinHost). TLS is enabled on both sites. In the iframe, Firefox says 'wcswanson.net will not allow Firefox to display the page if another site has embedded it.'
The code for the iframe is as follows:
<iframe width="99%" height="600px" src="https://wcswanson.net/deig3/" title="Downeast Intergroup Online Meetings"></iframe>
On the IIS Server the web.config file has the following code:
...<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="https://wcswanson.net/deig3/" />
</customHeaders>
</httpProtocol>
</system.webServer>
This does not work. Any suggestions?
Firefox says 'wcswanson.net will not allow Firefox to display the page if another site has embedded it.'
Because the page being linked to includes an X-Frame-Options: SAMEORIGIN HTTP response header that prevents the page being embedded in an IFRAME on another site.
<add name="X-Frame-Options" value="https://wcswanson.net/deig3/" />
This is not a valid value for this response header. (Only DENY and SAMEORIGIN are supported.)
Try removing the header:
<remove name="X-Frame-Options" />

Acumatica Screens in Wordpress iFrame

Does anyone know how to get Acumatica screens to be embedded in an iFrame in a wordpress site? When embedding an Acumatica screen in wordpress - I see the login screen however - after successful login I receive a refused to connect error.
I tried modifying the X-Frame in the web.config file - however still no difference after login. Does anyone know what changes need to be made on the Acumatica site to allow this? Or is it possibly a change that needs to happen in wordpress?
I realize that we should look at integrating the SSO but conceptually would think that the iFrames would work with or without SSO being setup yet or am I wrong in that assumption?
the answer provided by Hugues is very valid, but in the scope of Same Site Cookies.
With iFrame you would generally get following exception:
The loading of “https://yoursite.acumatica.com/Main?HideScript=On” in a frame is denied by “X-Frame-Options“ directive set to “SAMEORIGIN“.
For a while solution was to add an explicit header X-Frame-Options and in ALLOW-FROM specify an uri to the site you would like to allow to open Acumatica in iFrame, this however is now outdated: X-Frame-Options
Currently suggested way would be to use frame-ancestors directive of the Content-Security-Policy (frame-ancestors)
For applications that run on IIS, like Acumatica, it is done by finding in web.config
<httpProtocol>
<customHeaders>
...
And modify and add to this clause line like following example:
<add name="Content-Security-Policy" value="frame-ancestors 'self' https://my.site1.com *.site2.net http://localhost:82" />
This is just a syntax example that will allow the Acumatica to be open in iFrame on same domain, on my.site1.com, wildcard for all subdomains on site2.net and on even on the site deployed locally on the server that listens 82 port. Please use last one (http://localhost:82) only for testing purposes.
So the end result in your web.config should look similar to that block (based on SalesDemo deployment):
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="Content-Security-Policy" value="frame-ancestors 'self' https://yourWordPressUri" />
</customHeaders>
</httpProtocol>
Hope this is helping
I believe you are running into a same-site cookie policy error. If the issue was cross site scripting error you wouldn't see the login page.
Same site cookie policy can be disabled in the web config file:
https://learn.microsoft.com/en-us/aspnet/samesite/system-web-samesite#using-samesite-in-aspnet-472-and-48
Change the web.config file settings as follows:
Step 1: Open the web.config file, which is located in the application instance folder.
Step 2: Find the <system.web> section and add the following line to this section:
Note! The first occurrence of <system.web> located in the < location > tag is not the needed section.
Step 3: Add the text highlighted in bold to the following lines:
<formsAuth loginUrl="Frames/Login.aspx" timeout="60" requireSSL="true" />
<sessionState cookieSameSite="None" cookieless="UseCookies" mode="Custom" customProvider="PXSessionStateStore" timeout="60" sessionIDManagerType="PX.Owin.SessionIdManager, PX.Owin">

Access Control Allow Origin error with WordPress subdomain

I'm facing a problem with my WordPress website, it has a subdomain, blog.domain.com, when I access the blog I get the following error in my console:
Access to Font at www.domain.com/wp-content/themes/Divi/core/admin/fonts/modules.ttf from origin blog.domain.com has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource.
Currently, my website is hosted in Azure, I tried activating the option "Cross-Origin Resource Sharing - Cors" in my hosting options, it solved the issue, but it made the website a lot slower (16 sec), so I'm looking for an alternative to this issue.
If anyone has any idea how I can resolve this, I am opened to suggestions, I would appreciate it!
Thanks
If you use the windows azure web app, I suggest you could try to access below url:
https://yourwebappname.scm.azurewebsites.net/DebugConsole
Then you should go to the site\wwwroot and find the web.config file and add below config setting:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>

Content Security Policy error while loading Iframe

We are getting Content Security Policy error while loading an Iframe in our website.
The Iframe is loading a separate site in a virtual directory for our application. The application works fine when opened independently in a separate tab, but doesn't work in Iframe of parent site.
We tried adding a Meta tag <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" /> in the site Master page but it didn't work.
Also we added X-Frame-Options in IIS Http Response Header with Value "ALLOW-FROM https://virtual directory Ip Name/" but still no success.
The Issue is present in both IE and chrome.
Console Log in chrome :
Error Screenshot :
Try adding a config entry as below:
`<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy" value="default-src 'self';" />
</customHeaders>
</httpProtocol>
</system.webServer>`
default-src with 'self' indicates that loading content such as JavaScript, Images, CSS, Font's, AJAX requests, Frames, HTML5 Media from same origin. Likewise you can change the policy for the content in Iframe using child-src and mention the site you wish to load. If it is having same origin/domain u can use 'self'.
More details can be found here

Allow others to iframe my site

If others tries to iframe my site they get error "Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
". Do they have to change something, or I, or both?
I found there are options for X-Frame-Options :SAMEORIGIN,DENY,and allow only one site. Configuration :IIS8, ASP.NET MVC. Are there any global settings to allow others to iframe my site?
In your golbal.asax.cs set X-Frame-Options to AllowAll:
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("X-Frame-Options");
Response.AddHeader("X-Frame-Options", "AllowAll");
}
Since your website is the frame target, you would make all the changes to your website. As you will see below, this is quite simple.
Option 1 - Modify your web application's web.config file
Remove the X-Frame-Options custom header
Before:
<system.webServer>
...
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="AllowAll" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
After
<system.webServer>
...
<httpProtocol>
<customHeaders/>
</httpProtocol>
...
</system.webServer>
Option 2 - Log onto the web server and access IIS Manager
Open Internet Information Services (IIS) Manager.
In the Connections pane on the left side, expand the Sites folder
and select the site that you want to protect.
Double-click the HTTP Response Headers icon in the feature list in
the middle.
Select X-Frame-Options from the list
In the Actions pane on the right side, click Remove.
Click OK to save your changes.

Resources