Display MVC 5 web site in an IFrame

ASP.Net MVC 5 automatically adds a HTTP header called X-Frame-Options with the value SAMEORIGIN to your web application. That header is intended to prevent click jacking and makes sure your site can’t be loaded in an IFrame.
You can find more information about this header here.

HTTP header X-Frame-Option example

But if you want to display your web application in an IFrame, the header is a pain the ass. The information about how to disable this header is not easy to find, the only solution I found is on a Japanese blog.

The solution is easy to implement; you can disable the header by placing the following code in your Global.asax.cs file.

protected void Application_Start()

            // Disable the HTTP Header X-Frame-Options: SAMEORIGIN
            AntiForgeryConfig.SuppressXFrameOptionsHeader = true;


  1. After searching the web for about 4 hours, I finally stumbled upon this blog post. Can’t believe its this easy 🙂
    Thanx for sharing Joost!

  2. OMG..you are amazing. Can’t believe its that easy. Works like a charm! Been searching for it for hours.


  3. Thanks Joost you’re a life saver!
    This was a huge help and saved hours of frustration.

  4. I found this to be added to global.asax:
    protected void Application_PreSendRequestHeaders()
    Response.AddHeader(“X-Frame-Options”, “AllowAll”);

  5. Thanks A lot. this help me heaps because I was clueless when I had this issue and not many web searches are helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *