拒绝在一个框架中显示“https://mytestwebsite.com/?wa=wsignoutcleanup1.0”,因为它将“X-Frame-Options”设置为“DENY”

时间:2014-10-08 12:32:32

标签: asp.net-mvc-2 adfs2.0 x-frame-options

我使用ADFS 2.0作为使用asp.net mvc2和SQL Server 2012开发的应用程序的身份验证过程。为了解决问题:Clickjacking(又名跨站点框架或XSF),我们设置了X -Frame-options,其值为DENY,位于web.config文件中。

重现的步骤: 1.使用Chrome浏览器使用有效凭据登录应用程序。 2.系统显示应用程序登录页面。 3.单击F12以打开“开发人员工具”选项。 4.现在单击“注销”选项并导航到“控制台”窗口。 5.系统显示ADFS Signout页面,但我仍然在控制台窗口中收到错误,如下所述:

拒绝展示' https://mytestwebsite.com/?wa=wsignoutcleanup1.0'在一个框架中因为它设置了X-Frame-Options'到' DENY'。

在检查ADFS Sognout页面的ViewSource时,我看到了以下内容:

<iframe class="Test" src="https://mytestwebsite.com/?wa=wsignoutcleanup1.0">
</iframe>

有人能建议我解决上述问题的最佳方法吗?

1 个答案:

答案 0 :(得分:0)

一种选择是什么都不做。注销清理的重要部分是删除mytestwebsite.com的身份验证cookie,这仍然会完成,因为即使未显示生成的iframe内容,仍会处理http标头。

仅在以下情况下允许呈现iframe内容:

  • 您的网络应用程序执行进一步的下游注销清理。即它包含自己的iframe标签以注销其他应用程序,或
  • 您的STS使用&lt; img&gt;用于签名清理的标签而不是iframe,并且您希望WIF返回的绿色勾号图像出现,或者
  • 您真的,真的不希望浏览器控制台中出现无害的错误消息。

如果确实有必要,可以通过编程方式将x-frame-options DENY添加到除WS-federation signout cleanup之外的所有响应中。

对于ASP.NET MVC应用程序,您可以使用(在Global.asax.cs中):

    public override void Init()
    {
        base.Init();
        FederatedAuthentication.WSFederationAuthenticationModule.SigningOut += this.WSFederationAuthenticationModuleOnSigningOut;
    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        Response.Headers["X-Frame-Options"] = "DENY";
    }

    private void WSFederationAuthenticationModuleOnSigningOut(object sender, SigningOutEventArgs args)
    {
        if (args.IsIPInitiated)
        {
            Response.Headers.Remove("X-Frame-Options");
        }
    }
相关问题