【发布时间】:2016-07-19 21:05:05
【问题描述】:
我必须将旧网址(来自经典 Asp 网站)重定向到使用 ASP .NET MVC 生成的新网址。示例:
从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 }
);
这怎么可能?当我必须使用查询字符串重定向旧 url 时,这会导致问题。
【问题讨论】:
-
FWIW,最好通过 IIS 处理这个问题,因为某些遗留应用程序中发生的事情不是您的应用程序的域。它应该只关心它需要什么,而不是一些遗留应用程序。使用 IIS 中的 URL 重写模块。
标签: c# asp.net-mvc routing