【问题标题】:How to Redirect a page, outside of an Iframe using c#如何使用 c# 在 iframe 之外重定向页面
【发布时间】:2014-02-27 09:47:00
【问题描述】:

这些是应用程序中的页面

  1. Lo​​gin.aspx(不使用任何master)
  2. Home.aspx(使用主文件)。

master 中有一个 IFrame,它可以加载所有网页,如 page1.aspx、page2... 当用户浏览 page1.aspx 并且会话到期时,登录页面会在 IFrame 内加载,而应该在外部加载,我的意思是在 iFrame 之外。

我希望我的问题有点道理

Page_Init()
{
  if(Session["user"]==null)
   {
      Response.Redirect("~/Forms/Login.aspx");
   }
}

这里有针对 JS 的解决方案,如 window.top.location.href="..",但不知道如何实现。 如何使用 C# 解决此问题。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    这应该可行

    Page_Init()
    {
      if(Session["user"]==null)
       {
          string jScript = "window.top.location.href = '/Forms/Login.aspx';";
          ScriptManager.RegisterStartupScript(this, this.GetType(), "forceParentLoad", jScript, true);
          //Response.Redirect("~/Forms/Login.aspx");
       }
    }
    

    【讨论】:

    • 非常感谢。像魅力一样工作
    【解决方案2】:

    如果我们使用客户端脚本,但使用非客户端脚本,有很多方法:

    <a href="location" target="_top">Click here to continue</a> 
    
    <a href="location" target="_parent">Click here to continue</a>
    

    【讨论】:

      【解决方案3】:

      Iframe 中的 aspx 页面在不使用 javascript 的情况下不会引用它的父级。因此,您需要将其实现为 javascript。

      如果会话过期,您可以在尝试 Response.Redirect 的同一点简单地写出 JS,它应该可以正常工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-22
        • 2011-01-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多