【问题标题】:Redirect the entire page from MVC3 Razor iFrame page to a different URL将整个页面从 MVC3 Razor iFrame 页面重定向到不同的 URL
【发布时间】:2011-11-23 12:56:41
【问题描述】:

我有一个剃须刀页面https://myDomain1.com/myFrame.cshtml,上面有一个“继续”按钮

此剃须刀页面是另一个 parent.cshtml

中的 iframe

当我点击“继续”按钮时,我想将我的整个页面(包括父页面)重定向到 https://myDomain2.com/default

下面给出的是我的控制器中的 ActionResult

[HttpPost]
    public ActionResult myFrame(TestViewModel model)
    {

      Response.Redirect("https://myDomain2.com/default");

       return View(model);
    }

使用我上面的代码,只有页面的 iframe 部分正在重定向,但我的要求是将整个页面重定向到 https://myDomain2.com/default 我的问题是,我想将整个页面(包括父页面)重定向到 https://myDomain2.com/default

请帮助我如何将整个页面重定向到不同的域 URL

【问题讨论】:

    标签: asp.net-mvc-3 razor


    【解决方案1】:

    如果您必须使用此解决方案(坚持使用框架),只需包含 javascript 内容结果 - 类似以下内容:

    [HttpPost] public ActionResult myFrame(TestViewModel model) { return Content("<html><script>window.top.location.href = "http://www.whatever.com"; </script></html>"); }

    您的框架必须在同一个域中才能正常工作。

    【讨论】:

      【解决方案2】:

      HTTP 不允许您在响应中指定目标帧。

      改为在原始&lt;form&gt; 中设置target="_top",或在目标页面中放置一个Javascript frame-buster。

      【讨论】:

      • 或者,更好的是,停止使用框架。
      • SLaks -- 有时我们必须处理遗留系统。
      猜你喜欢
      • 1970-01-01
      • 2015-08-14
      • 2012-10-15
      • 1970-01-01
      • 2021-02-21
      • 2015-10-22
      • 2013-02-08
      • 2023-02-02
      相关资源
      最近更新 更多