2014-11-03 76 views
1

是否可以在iFrame中执行response.redirect以重定向整个页面,以便目标页面可全屏查看并且不包含在iFrame中?ASP.NET iFrame Response.Redirect父窗口

下面是后面

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

    } 
} 

当前代码任何帮助将不胜感激:-)

回答

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); 
+0

谢谢你,我试过了,但得到了验证错误说'不能访问非静态方法“的RegisterClientScriptBlock”静态context'。 – iggyweb 2014-11-04 04:45:34

+0

因此将一个参数传递给方法public static void RegisterSomeScript(Page page) page.ClientScript.RegisterStartupScript(“Load”, “”); }' – 2014-11-04 06:03:39

+0

道歉,但现在我越来越'无法解决方法'RegisterClientScriptBlock(字符串,字符串)“我错过了什么? – iggyweb 2014-11-04 07:37:02