ASP.NET MVC 4 - 301重定向的RouteConfig.cs [英] ASP.NET MVC 4 - 301 Redirects in RouteConfig.cs

查看:971
本文介绍了ASP.NET MVC 4 - 301重定向的RouteConfig.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加到RouteConfig.cs文件的路径在ASP.NET MVC应用程序4执行301永久重定向到另一条路线?

How can I add a route to the RouteConfig.cs file in an ASP.NET MVC 4 app to perform a permanent 301 redirect to another route?

我想某些不同的路线在同一个控制器的动作指向 - 它似乎是一个301将是这个最佳实践,专门为搜索引擎优化

I would like certain different routes to point at the same controller action - it seems a 301 would be best practice for this, specially for SEO?

感谢。

推荐答案

您必须使用永久重定向,这里是一个例子:

You have to use RedirectPermanent, here's an example:

public class RedirectController : Controller
{

    public ActionResult News()
    {

        // your code

        return RedirectPermanent("/News");
    }
}

在全局ASAX:

in the global asax:

    routes.MapRoute(
        name: "News old route",
        url: "web/news/Default.aspx",
        defaults: new { controller = "Redirect", action = "News" }
    );

这篇关于ASP.NET MVC 4 - 301重定向的RouteConfig.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆