【问题标题】:ASP.NET iFrame Response.Redirect Parent WindowASP.NET iFrame Response.Redirect 父窗口
【发布时间】:2014-12-30 14:52:06
【问题描述】:

是否可以在 iFrame 中执行 response.redirect 以重定向整个页面,以便目标页面可以全屏查看,而不包含在 iFrame 中?

下面是当前的代码

public partial class ServerResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

任何帮助将不胜感激:-)

【问题讨论】:

    标签: html asp.net iframe


    【解决方案1】:

    没有。

    Response.Redirect 是一个服务器命令,它发送 (302 ?) 标头告诉客户端重定向。

    您在 iframe 世界中。您不能告诉服务器:“嘿,当您向我发送数据时 - 将其发送到父 iframe”

    但是你能做什么,是这样的:

    protected void Page_Load(object sender, EventArgs e) {
       ClientScriptManager.RegisterClientScriptBlock(this.GetType(), 
           "aaa", "window.parent.location = 'http://yoursite.com'", true);
    }
    

    但您必须从服务器中删除 response.redirect。

    编辑

    var page = HttpContext.Current.Handler as Page;
                if (page != null) page.ClientScript .RegisterClientScriptBlock(typeof(string), "Redirect", "window.parent.location='" + url + "';", true);
    

    【讨论】:

    • 谢谢,我试过了,但出现验证错误,提示 Cannot access non-static method 'RegisterClientScriptBlock' in static context
    • 所以给方法public static void RegisterSomeScript(Page page) { page.ClientScript.RegisterStartupScript("Load", "<script>.........</script>"); }传递一个参数
    • 抱歉,但现在我收到Cannot resolve method 'RegisterClientScriptBlock(string, string)' 我错过了什么吗?
    • 我也试过var cm = Page.ClientScript; cm.RegisterClientScriptBlock(GetType(), "Redirect", "window.parent.location='" + url + "';", true);代码确实验证了,但没有触发。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多