为什么Response.Redirect的不定向外部URL? [英] Why does Response.Redirect not redirect external URL?

查看:207
本文介绍了为什么Response.Redirect的不定向外部URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:用户当前在以下页面: http://myinternaldomain.com/page/

Context: User is currently in the following page: http://myinternaldomain.com/page/

问题:
当用户点击上面网页上的按钮,处理这个点击应该做一些处理,用户重定向到一个外部域控制器的MVC方法说google.com。我想下面分别对2陈述,但两者调用的外部URL附加到当前内部页面,用户是:

Issue: When user clicks on a button in the above page, the MVC Controller method that handles this click should do some processing and redirect the user to an external domain say google.com. I tried the 2 statements below separately but both calls append the external url to the current internal page that the user is on:

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

以上两种语句导致用户使用重定向到:
    <一href=\"http://myinternaldomain.com/page/www.google.com\">http://myinternaldomain.com/page/www.google.com
而不是仅仅将用户重定向到www.google.com。

Both of the above statements result in user getting redirected to: http://myinternaldomain.com/page/www.google.com instead of just redirecting the user to www.google.com.

我是什么在这里失踪?

推荐答案

您需要preFIX你的URL的http://,像这样的:

You need to prefix your URL with "http://", like this:

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

这篇关于为什么Response.Redirect的不定向外部URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆