我使用 C# 控制器作为网络服务。
在其中我想将用户重定向到外部网址。
我该怎么做?
Tried:
System.Web.HttpContext.Current.Response.Redirect
但没有成功。
使用控制器的重定向() http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirect.aspx method.
public ActionResult YourAction()
{
// ...
return Redirect("http://www.example.com");
}
Update
您无法直接从 ajax 响应执行服务器端重定向。但是,您可以返回带有新 url 的 JsonResult 并使用 javascript 执行重定向。
public ActionResult YourAction()
{
// ...
return Json(new {url = "http://www.example.com"});
}
$.post("@Url.Action("YourAction")", function(data) {
window.location = data.url;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)