日期:2014-05-17  浏览次数:20457 次

请问在mvc里怎么做301跳转。谢谢。
路由都已经配置好了
原来的地址是 /news/list/?pageindex=1&categoryid=0
新的地址是 /news/1-0

现在单独请求新地址可以访问
现在要求输入旧地址可以跳转到新地址上,Status Code是301
请问怎么实现,谢谢。

------解决方案--------------------
如果是MVC3的话
直接返回return new HttpStatusCodeResult(301);
然后在web.config 里自定义error的设置
------解决方案--------------------
public class TestFilter : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(xxx.=xxx.xxx){//判段是否是过期路径
filterContext.Response.StatusCode = 301; 

}
 }
可以用全局过滤实现。
------解决方案--------------------
用httpwatch看