我对 X-Frame-Options http header 有疑问。
我使用 MVC 5,因此 SAMEORIGIN 选项会自动添加到 Http 响应的 header 中。
我仍然想使用默认选项,我不想在 Application_Start 中使用以下行:
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
我想在 Controller 级别的某些特定操作中删除 X-Frame-Options header ,代码如下:
base.HttpContext.Response.Headers.Remove("X-Frame-Options");
但是,它不起作用。
你知道我怎样才能删除它吗?
我们将不胜感激。
最佳答案
调查问题后,我注意到可以创建一个覆盖 OnResultExecuted 方法的 ActionFilter,我可以在其中删除该 http header :
public class AllowIframeFromUriAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//...
filterContext.HttpContext.Response.Headers.Remove("X-Frame-Options");
base.OnResultExecuted(filterContext);
}
}
它有效,所以我想分享解决方案。
关于c# - 如何从响应中删除 X-Frame-Options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32436588/