ASP.NET MVC 4 - RouteConfig.cs 中的 301 重定向 [英] ASP.NET MVC 4 - 301 Redirects in RouteConfig.cs
本文介绍了ASP.NET MVC 4 - RouteConfig.cs 中的 301 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何向 ASP.NET MVC 4 应用程序中的 RouteConfig.cs 文件添加路由,以执行到另一条路由的永久 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 是最好的做法,特别是对于 SEO?
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?
谢谢.
推荐答案
你必须使用 RedirectPermanent,这里有一个例子:
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 - RouteConfig.cs 中的 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文