What is the default policy within an asp.net mvc application? Also how are CORS and X-Frame-Options related?
If I create a new MVC web app (hosted in IIS) on port e.g. 21232, I add an iframe to the index views with a source set to my local IIS e.g.
<iframe src="http://localhost/iisstart.htm" width="800" height="100"/>
This works fine (even though on a different port to the web application).
If I now change the iframe source to be something completely external, e.g.
<iframe src="http://www.google.com" width="800" height="100"/>
This now displays an empty iframe. If I look in the Chrome dev tools (Chrome used in both examples) I see an error in the console
Refused to display 'https://www.google.co.uk' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
- Why did the first URL work when the address is on a different port to the hosting page?
- How do X-Frame-Options relate to CORS? I tried adding the following to my web.config (see ref enable cors in IIS)
<add name="Access-Control-Allow-Origin" value="*" />
Which made no difference. Looks as if I need to add the following to the Application_Start in the global.asax.cs
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
Are X-Frame-Options specifically iframe related?