Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to external URI from ASP.NET MVC controller

People also ask

How redirect external URL from view in MVC?

You can redirect to an external URL by using Redirect Method() or via Json Result. Asp.net MVC redirect to URL: You can do URL redirect in mvc via Controller's Redirect() method. The following example, I have given redirection to google page.

How we can redirect to another page or controller?

Redirect() method The first method od redirecting from one URL to another is Redirect(). The Rediect() method is available to your controller from the ControllerBase class. It accepts a target URL where you would like to go.

What is the redirect method in MVC?

RedirectToAction(String, String, Object)Redirects to the specified action using the action name, controller name, and route dictionary.


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.


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.


Maybe the solution someone is looking for is this:

Response.Redirect("/Sucesso")

This work when used in the View as well.