Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net MVC 301 Redirects

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?

like image 413
LiamB Avatar asked Feb 11 '11 09:02

LiamB


People also ask

What is 301 redirect asp net?

301 is an HTTP status code sent by a web server to a browser. A 301 signals a permanent redirect from one URL to another, meaning all users that request an old URL will be automatically sent to a new URL.

Why is my 301 Moved Permanently?

The HyperText Transfer Protocol (HTTP) 301 Moved Permanently redirect status response code indicates that the requested resource has been definitively moved to the URL given by the Location headers. A browser redirects to the new URL and search engines update their links to the resource.

How do I redirect to an action in ASP NET MVC?

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


2 Answers

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.

like image 81
amelvin Avatar answered Sep 28 '22 21:09

amelvin


If you are using IIS7, I would recommend using the official IIS7 URL Rewrite module.

  • Using the URL Rewrite Module
  • Using URL Rewrite Module 2.0
like image 26
Charlino Avatar answered Sep 28 '22 21:09

Charlino