解决方法
创建一个继承自ActionResult的类…
public class PermanentRedirectResult : ActionResult { public string Url { get; set; } public PermanentRedirectResult(string url) { this.Url = url; } public override void ExecuteResult(ControllerContext context) { context.HttpContext.Response.StatusCode = (int)HttpStatusCode.MovedPermanently; context.HttpContext.Response.RedirectLocation = this.Url; context.HttpContext.Response.End(); } }
然后用它……
public ActionResult Action1() { return new PermanentRedirectResult("https://stackoverflow.com"); }
一个更完整的答案将重定向到路线… Correct Controller code for a 301 Redirect