ASP.NET MVC 2.0 supplies a RedirectResult which returns a HTTP 302 temporary redirect. In many cases you really want a HTTP 301 permanent redirect result.
The following class will do the job:
using System.Web.Mvc; ///I included this class in the TTC Tools which you can find on github./// Redirects using a 301 permanent redirect HTTP status code. /// public class PermanentRedirectResult : RedirectResult { public PermanentRedirectResult(string url) : base(url) { } public override void ExecuteResult(ControllerContext context) { base.ExecuteResult(context); context.HttpContext.Response.StatusCode = 301; } }
It can be used in the same manner as RedirectResult.
Next entry: Internet Explorer 8, compatibility view, and the local intranet zone
Previous Entry: What to check when ClientBuildManager.GetCompiledType returns null
Latest entries:
Create absolute URLs using ASP.NET MVC
Comments
My Links
Tags
Follow me
About
Powered by FoxBlog
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2011, Nathan Fox