【问题标题】:asp.net MVC, redirect to view, view open new window to external url, it's getting treated as a viewasp.net MVC,重定向到视图,查看打开新窗口到外部 url,它被视为视图
【发布时间】:2012-09-06 21:42:37
【问题描述】:

试图拼凑一个快速而肮脏的页面,以便在新窗口中重定向到另一个网站。

所以我在会话中存储一个 url,从 mvcSiteMap 重定向到页面,点击页面...

运行这个javascript

    $(document).ready(function () {
        window.open( '@HttpContext.Current.Session["EisUrl"].ToString();' );
    });


</script>

}

我没有打开一个指向 google.com 的新窗口,而是看到与此消息相同的窗口。

未找到视图“http://google.com”或其主视图,或者没有视图引擎支持搜索到的位置。搜索了以下位置: ~/Views/ReportsManagement/http://google.com.aspx ~/Views/ReportsManagement/http://google.com.ascx ~/Views/Shared/http://google.com.aspx ~/Views/Shared/http://google.com.ascx ~/Views/ReportsManagement/http://google.com.cshtml ~/Views/ReportsManagement/http://google.com.vbhtml ~/Views/Shared/http://google.com.cshtml ~/Views/Shared/http://google.com.vbhtml

所以它把我的外部 URL 当作它仍然在网站内部......

这看起来应该很简单......显然我错过了一些明显的东西。

感谢任何帮助。

【问题讨论】:

  • 您的 jovialscript 正在访问您的 ASP.NET MVC 服务器,并尝试执行控制器。
  • @DarthVader 你什么意思?他接受了他提出的问题的 2/3 的答案。
  • 为什么是负面的代表?我回答了它,它已经有了答案,所以我不能删除它,尽管我试图......这种行为是不合逻辑的,以至于其他人可能会再次碰到它,所以答案甚至可能会有所帮助......我不知道该怎么做。

标签: c# javascript asp.net-mvc


【解决方案1】:

确保从会话中呈现的内容是您所期望的正确且格式正确的 URL。我通常也使用window.location 在javascript中重定向。

【讨论】:

    【解决方案2】:

    也许完全超出范围,但您不能在 ActionResult 中执行此操作吗?

    return Redirect("http://www.google.com");
    

    【讨论】:

    • 对不起,如果我不清楚,我需要打开一个新窗口,然后将其重定向到外部网页(用于测试 google.com)
    【解决方案3】:

    试试

    window.location = '@HttpContext.Current.Session["EisUrl"].ToString()';

    【讨论】:

    • 试过Window.location,它做同样的事情。我正在尝试打开一个新窗口并转到我的 MVC 应用程序之外的 url ......我错过了什么?我发誓我以前做过这个……
    • 如何设置Session变量?
    • HttpContext.Current.Session[ "EisUrl" ] = url;
    • 这完全是蛮力,试图简单地做所有事情 string url = "google.com";
    • 好吧,所以宁愿这样做:url = "http://www.google.com";。它不会在新窗口中打开它。为此,您需要坚持使用 window.open 枪支。
    【解决方案4】:

    我想通了,我是 id 10 t,

    我在视图中有这个(剃须刀)

    @model string
    

    这个在控制器中

    public ActionResult GetEisReportRedirect()
            {
                string url =  eisReportBLLHdl.DoGetEisReportRedirect(  );
    
                return View( url );// i was passing url here to the view
            }
    

    所以它试图将字符串作为模型传递,我决定我不确定确切的行为并切换到将其放入会话中......但将它们留在原处。

    由于某种原因,字符串被解析为 URL,新窗口没有打开这一事实应该是它提前脱轨的线索。

    当我从模型中删除该行并从返回 View()...

    感谢大家的帮助!

    【讨论】:

      猜你喜欢
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      • 1970-01-01
      • 2023-03-09
      • 2016-05-21
      相关资源
      最近更新 更多