MVC 中301永久重定向

public class PermanentRedirectResult : ViewResult
{
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(); 
} 

}

使用
public class ProductController : Controller
{

    public ActionResult JingSuan()
    {
        return new PermanentRedirectResult("/Controller/Action/参数");
    }

}

posted @ 2016-04-25 15:43  门外客  阅读(316)  评论(0编辑  收藏  举报