What is the difference between Redirect, RedirectToAction and RedirectToRoute?

ASP.NET MVC Controllers & Actions Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

All send an HTTP redirect (302 by default). Redirect("/some/url") takes a raw URL. RedirectToAction("Index", "Home") builds the URL from an action/controller — refactor-safe. RedirectToRoute(new { ... }) builds it from named route values. Prefer RedirectToAction so route changes don't break links.

They all issue a 302 redirect, they just differ in how you specify the target. Redirect takes a literal URL string. RedirectToAction builds the URL from an action and controller name, so if I change a route the link still works — that's my default. RedirectToRoute uses named route values. After a successful form POST I always RedirectToAction to the GET action — the post-redirect-get pattern — so refreshing the page doesn't resubmit. And if I'm redirecting to a returnUrl from the query string, I use LocalRedirect so someone can't turn it into an open redirect to a phishing site.

  • Use RedirectToAction(nameof(Index)) after a successful POST — the Post/Redirect/Get pattern — so a browser refresh doesn't re-submit the form.
  • *Permanent variants send 301 for genuinely moved resources (SEO).
  • LocalRedirect rejects absolute external URLs — use it when redirecting to a user-supplied returnUrl to prevent open-redirect attacks.
  • Carry a status message across the redirect with TempData.