use*_*498 163 url asp.net-mvc redirect
我正在尝试从操作方法重定向到外部URL但无法使其工作.有人可以解释我的错误吗?
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);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,克里斯
Yur*_*ich 323
如果您正在谈论ASP.NET MVC,那么您应该有一个返回以下内容的控制器方法:
return Redirect("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)
否则,我们需要有关您在重定向中获得的错误的更多信息.我会逐步确保网址不是空的.
sto*_*tom 15
使用JavaScript
public ActionResult Index()
{
return Content("<script>window.location = 'http://www.example.com';</script>");
}
Run Code Online (Sandbox Code Playgroud)
注意:正如@Jeremy Ray Brown所说,这不是最佳选择,但在某些情况下您可能会觉得有用.
希望这可以帮助.
归档时间: |
|
查看次数: |
179917 次 |
最近记录: |