MVC 5 prevents access to content via Iframe

后端 未结 5 808
灰色年华
灰色年华 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:25

    Personally, I don't think it's a good idea to disable the X-Frame-Options across the whole site.I've created an ASP.NET MVC filter which removes this header and I simply apply this filter to the portions of the site that are used in iFrames e.g. widgets.

    public class AllowDifferentOrigin : ActionFilterAttribute, IActionFilter
    {
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            filterContext.HttpContext.Response.Headers.Remove("X-Frame-Options");
            base.OnResultExecuted(filterContext);
        }
    }
    

提交回复
热议问题