cómo redirigir a url externas desde el controlador c #
Estoy usando un controlador c# como servicio web.
En él quiero redirigir al usuario a una url externa.
¿Cómo lo hago?
Intentado:
System.Web.HttpContext.Current.Response.Redirect
Pero no funcionó.
60
Author: Elad Benda, 2012-03-16
3 answers
Usa el método Redirect () del Controlador.
public ActionResult YourAction()
{
// ...
return Redirect("http://www.example.com");
}
Update
No puede realizar directamente una redirección del lado del servidor desde una respuesta ajax. Sin embargo, puede devolver un JsonResult con la nueva url y realizar el redireccionamiento con javascript.
public ActionResult YourAction()
{
// ...
return Json(new {url = "http://www.example.com"});
}
$.post("@Url.Action("YourAction")", function(data) {
window.location = data.url;
});
103
Author: jrummell,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-23 13:37:23
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-23 13:37:23
Prueba esto:
return Redirect("http://www.website.com");
8
Author: Tom Chantler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-16 14:35:16
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-16 14:35:16
Si está utilizando MVC, entonces sería más apropiado usar RedirectResult en lugar de usar Response.Redirigir.
public ActionResult Index() {
return new RedirectResult("http://www.website.com");
}
Referencia - https://blogs.msdn.microsoft.com/rickandy/2012/03/01/response-redirect-and-asp-net-mvc-do-not-mix/
7
Author: EndlessSpace,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-25 15:55:54
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-25 15:55:54