What is the difference between the following two controller ActionResult return statements:
return new RedirectResult("http://www.google.com", false);
and
return Redirect("http://www.google.com");
What is the difference between the following two controller ActionResult return statements:
return new RedirectResult("http://www.google.com", false);
and
return Redirect("http://www.google.com");
They do the same thing. The Redirect method of the controller creates a new RedirectResult. If you instantiate the RedirectResult you also have the ability to add a parameter which determines whether the redirect is permanent (or not).
straight from the source
The second argument determines whether the response is a 302 (temporary) or 301 permanent redirection. By default, the value is
false
.The second method is on
Controller
and is simply a convenience method. This method has been around for a number of versions of MVC (as far back as at least 2), but IIRC, the addition of the Permanent part toRedirectResult
I think has come in in MVC 4 (I don't recall seeing it in MVC 3).this.Redirect(string url) - It will internally create new object of RedirectResult class and do temporary redirection.
new RedirectResult(string url, bool permanent) - It will redirect but gives you an option to redirect permanently or temporary.