【问题标题】:Response.REdirect within an IFrameIFrame 中的 Response.REdirect
【发布时间】:2011-02-16 04:50:49
【问题描述】:

我遇到了从 IFrame 中的按钮重定向我的 asp 页面的情况。

按钮点击事件中的Response.Redirect重定向IFrame而不是整个页面。

谢谢, 毗湿奴

【问题讨论】:

    标签: c# asp.net iframe response.redirect


    【解决方案1】:

    您可以将target="_top" 添加到html <form> 元素,或使用javascript 重定向window.top.location = '/path'

    如果您有多个 iframe 页面,您可能想要创建一个通用页面,我们称之为FrameRedirector.aspx。将此代码放在正文中:

    <script type="text/javascript">
      window.top.location = '<%=Server.UrlDecode(Request.QueryString["url"])%>';
    </script>
    

    然后,将Response.Redirect 代码替换为

    string redirect = "/path/to/redirect.aspx?foo=bar";
    Response.Redirect("~/FrameRedirector.aspx?url=" + Server.UrlEncode(redirect));
    

    【讨论】:

    • 请注意,此解决方案原样不够安全,无法防止 XSS/重定向验证
    猜你喜欢
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 2010-10-08
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    相关资源
    最近更新 更多