The RedirectResult
will give you a 302, however if you need a 301 use this result type:
public class PermanentRedirectResult : ActionResult
{
public string Url { get; set; }
public PermanentRedirectResult(string url)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException("url is null or empty", "url");
}
this.Url = url;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.HttpContext.Response.StatusCode = 301;
context.HttpContext.Response.RedirectLocation = Url;
context.HttpContext.Response.End();
}
}
Then use it like mentioned above:
public PermanentRedirectResult Redirect()
{
return new RedirectResult("http://www.google.com");
}
Source (as it's not my work): http://forums.asp.net/p/1337938/2700733.aspx