Reputation: 6133
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);
}
Thanks, Chris
Upvotes: 188
Views: 267092
Reputation: 168
Maybe the solution someone is looking for is this:
Response.Redirect("/Sucesso")
This work when used in the View as well.
Upvotes: 2
Reputation: 6609
Using JavaScript
public ActionResult Index()
{
return Content("<script>window.location = 'http://www.example.com';</script>");
}
Note: As @Jeremy Ray Brown said , This is not the best option but you might find useful in some situations.
Hope this helps.
Upvotes: 16
Reputation: 68667
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.
Upvotes: 380