Reputation: 1729
I have to redirect old url (from a Classic Asp website) to the new ones generated using ASP .NET MVC. Example:
From localhost/news.asp
to localhost/News
I addend the following rule:
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();
}
But the rules "it uses" is the following:
routes.MapRoute(
"Normal",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
How is this possible? This thing causes problem when I have to redirect legacy urls with query string.
Upvotes: 1
Views: 446
Reputation: 93
routes.Redirect(r => r.MapRoute("", "news.asp")).To(routes.Map("", "Home/Index", new { controller = "Home", action = "Index" }));
This is how I redirect my old .asp routes
Upvotes: 2