我正在尝试删除X-Frame-Options SAMEORIGIN
标头或将其设置为ALLOWALL
。
我已经在我的web.config
中设置了它,并且在站点的IIS响应头中也设置了它,但是我仍然在我的浏览器中获得X-Frame-Options SAMEORIGIN
,并且iframe内容不呈现。
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<add name="Cache-Control" value="public" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="X-Frame-Options" value="ALLOWALL" />
</customHeaders>
</httpProtocol>
火狐和Chrome也是如此。
有没有其他地方我应该寻找它或可以修改它?
发布于 2019-12-10 18:50:55
转到Global.asax.cs中的Application_Start()
并添加以下行
System.Web.Helpers.AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
但请注意,这意味着任何人都可以在iframe中使用您的应用程序。因此,使用下面的代码添加一个新文件是值得的:
using System.Web.Mvc;
namespace MyApplication
{
public class NoIframeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.HttpContext.Response.Headers.Set("X-Frame-Options", "SAMEORIGIN");
}
}
}
将以下行添加到FilterConfig.cs中的RegisterGlobalFilters方法:
filters.Add(new NoIframeAttribute());
现在它已经安全地返回到您的应用程序中,您可以使用以下命令删除应用程序中需要的任何位置的remove选项
Response.Headers.Remove("X-Frame-Options");
https://stackoverflow.com/questions/56434599
复制相似问题