我必须将旧URL(从Classic Asp网站)重定向到使用ASP .NET MVC生成的新URL。例如:
从localhost/news.asp
到localhost/News
我加上以下规则:
routes.MapRoute(
"legacyUrl1",
"{controller}.asp/{action}/{id}",
new { controller = "News", action = "RedirectLegacyURL", id = UrlParameter.Optional }
);
//in news controller
public void RedirectLegacyURL(string id)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "news/" );
Response.End();
}
但规则"它使用"如下:
routes.MapRoute(
"Normal",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这怎么可能?当我必须使用查询字符串重定向旧网址时,这会导致问题。
答案 0 :(得分:2)
routes.Redirect(r => r.MapRoute("", "news.asp")).To(routes.Map("", "Home/Index", new { controller = "Home", action = "Index" }));
这就是我重定向旧的.asp路由的方式