MVC 5 prevents access to content via Iframe

后端 未结 5 791
灰色年华
灰色年华 2020-12-01 12:01

Ever since the upgrade from MVC4 to MVC5, I have noticed an extra server header added to my web pages:

X-Frame-Options: SAMEORIGIN

I understand security bene

5条回答
  •  自闭症患者
    2020-12-01 12:29

    Try something like this in Global.asax:

    protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
     {
       HttpContext.Current.Response.Headers.Remove("X-Frame-Options");
     }
    

    EDIT:

    Look at answer of Colin Bacon. It is more correct than mine.

    In short - don't remove this header if you don't want to run your site in IFRAME because it will open forgery vulnerability. But if you still want to remove it - use AntiForgeryConfig.SuppressXFrameOptionsHeader = true; in Application_Start, it is more cleaner way for doing this.

提交回复
热议问题