Asp.Net MVC 301 Redirects

LiamB picture LiamB · Feb 11, 2011 · Viewed 12.4k times · Source

We used to use ISAPI Re-Write (Infact its still on our server) although it doesnt work with ASP.Net MVC (Somthing to do with 'euxd' get param).

We need a relaiable way to implement simple 301 redirects, when we change the site structure, upload a new site etc. Any suggestions?

Ok, it I wanted to redirect /SomeFolder/SomePage.HTML?Param1=X to /NewPage/X

How can we do that?

Answer

amelvin picture amelvin · Feb 11, 2011

In MVC 3 there are three new redirect methods that can be used in controllers to redirect permanently (produce a 301); as opposed to the 302s (temporary redirect) produced by the MVC 2 redirects.

  • RedirectPermanent
  • RedirectToActionPermanent
  • RedirectToRoutePermanent
public ActionResult OldAction()
{
  return RedirectPermanent(urlname);
}

There is a great tutorial in the Controllers section of these walkthroughs on PluralSight.