为什么Response.Redirect不重定向外部URL?

时间:2011-08-23 05:46:24

标签: c# asp.net redirect

上下文:用户当前位于以下页面:http://myinternaldomain.com/page/

问题: 当用户单击上一页中的按钮时,处理此点击的MVC Controller方法应该进行一些处理并将用户重定向到外部域,例如google.com。我分别尝试了下面的两个语句,但两个调用都将外部URL附加到用户所在的当前内部页面:

System.Web.HttpContext.Current.Response.Redirect("www.google.com"); // plain old HttpResponse object


return Controller.Response.Redirect("www.google.com"); // MVC Controller's response object

以上两个陈述都会导致用户被重定向到:     http://myinternaldomain.com/page/www.google.com 而不是仅仅将用户重定向到www.google.com。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:12)

您需要在网址前加上“http://”,如下所示:

Controller.Response.Redirect("http://www.google.com");
相关问题