Sonu K
Sonu K

Reputation: 2802

What are different Redirect methods in ASP.NET MVC?

Can anyone tell me about the different Redirect methods in ASP.NET MVC 5? I have user Redirect, RedirectToAction, RedirectPermanent, but I am wondering which one to use in which scenario.

Please describe all the Redirect methods available in ASP.NET MVC 5 apart from these.

Upvotes: 0

Views: 1439

Answers (2)

Yehia Elhawary
Yehia Elhawary

Reputation: 598

You can using response to redirect like:

Response.Redirect("yoururl");//you can use route like: Response.Redirect("~/Home/About");

Upvotes: 1

Aik
Aik

Reputation: 3738

  • Redirect - Redicect to the specified url (HTTP 302)
  • RedirectPernament - Same as Redicect but with HTTP 301 response
  • RedirectToAction - Redirect to the action (HTTP 302)
  • RedirectToActionPernament - Same as RedirectToAction but with HTTP 301 response
  • RedirectToRoute - Redicect to the route (HTTP 302)
  • RedirectToRoutePernament - Same as RedirectToRoute but with HTTP 301 response

All redirect internally do the same (HTTP 302 or HTTP 301). Methods differ how they resolve url to redirect:

  • Redirect use url passed as parameter
  • RedirectToAction generates url from action name or action name and controller name
  • RedirectToRoute generates url from route name

Upvotes: 3

Related Questions