【问题标题】:How to restrict my site to be used from other sites by iframe in ASP.NET如何在 ASP.NET 中通过 iframe 限制我的网站从其他网站使用
【发布时间】:2014-06-08 17:08:18
【问题描述】:

我不希望任何人在未经我许可的情况下使用 iframe 内容。如何仅允许我选择的域能够将 iframe 嵌入页面内容?

我的问题是这样的:在我的 asp.net 网页中,一个 iframe 和这个 iframe 动态加载。 当我的网页第一次加载时,我的网页网址是:http://examle.com,而我的 iframe src 属性网址是:http://example.com/anotherwebpage.aspx

我想限制任何人未经我的许可不得更改我的 iframe src 属性 url。如何做到这一点。

【问题讨论】:

    标签: javascript jquery html asp.net iframe


    【解决方案1】:

    使用The X-Frame-Options response header

    在您希望防止在其他网站的框架中显示的文档的 HTTP 响应中包括:

    The X-Frame-Options: SAMEORIGIN
    

    那么http://example.com/ 可以嵌入http://example.com/foohttp://example.net/ 不能。

    (请注意,旧浏览器会忽略此标头,但它会在足够多的现代浏览器上阻止它,使其他网站不值得尝试嵌入它)。

    【讨论】:

    • 太棒了,但第二个仍然是一个解决方案!
    • 我已经尝试过这个选项,但我没有得到解决方案....请给我另一个选择...
    • 我已经在 web.config 文件中使用了这个代码 ...... 但是当我在 iframe src 属性中添加其他网站 url 然后 iframe 在我的网站 iframe 中显示其他网站时它不起作用。
    • 为什么会有问题?
    • 实际上我想限制另一个域站点添加到我的网站 iframe 中。但我无法做到这一点。在 web config 中使用 x 框架选项后,我的网站 iframe 仍然添加其他站点它。
    【解决方案2】:

    将此添加到您的 Web.config。这将为您的 http 响应添加另一个标头。

    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="X-Frame-Options" value="sameorigin"/>
            </customHeaders>
        </httpProtocol>
    </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 2021-04-01
      • 1970-01-01
      • 2021-07-08
      • 2012-11-25
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 2014-07-13
      相关资源
      最近更新 更多