从 ASP.NET MVC 控制器重定向到外部 URI
问题描述:
我正在尝试从操作方法重定向到外部 url,但无法使其正常工作.有人能解释一下我的错误吗?
I'm trying to redirect to external url from an action method but can't get it to work. Can anybody shed some light on my error?
public void ID(string id)
{
string url = string.Empty;
switch (id)
{
case "DB2FCB11-579F-4DA2-A68C-A6495B9BAAB5":
url = "http://www.somesite.com";
break;
}
Response.Redirect(url, true);
}
谢谢,克里斯
答
如果您在谈论 ASP.NET MVC,那么您应该有一个返回以下内容的控制器方法:
If you're talking about ASP.NET MVC then you should have a controller method that returns the following:
return Redirect("http://www.google.com");
否则,我们需要有关您在重定向中遇到的错误的更多信息.我会逐步确保该网址不为空.
Otherwise we need more info on the error you're getting in the redirect. I'd step through to make sure the url isn't empty.