Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Archive for July, 2016

Refused to display url in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN’.

Posted by Viral Sarvaiya on July 21, 2016


Hello All,

After a very log time adding new post in my blog.

Few days before I get one problem that my MVC website is not opening in Iframe.

for eg. my URL is http://localhost/websitename/page

This URL I am opening in Iframe tab like below.


<iframe src="http://localhost/websitename/page" width="500" height="500" />

and getting error as below.

Refused to display ‘http://localhost/websitename/page’ in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN’.

and it is not opening my website in IFrame.

Solution-1:

Open Global.asax.cs file, and add one method as below.

protected void Application_PreSendRequestHeaders()
 {
 Response.Headers.Remove("X-Frame-Options");
 Response.AddHeader("X-Frame-Options", "AllowAll");
 }

This will open website in Iframe.

Solution-2:


protected void Application_Start()
 {
 AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
 }

This will open website in IFrame

Hope this will helps you.

Thanks.

Advertisements

Posted in .Net, ASP.NET, C#, MVC | Tagged: , , , , | Leave a Comment »

 
%d bloggers like this: