1
我有一个网站的HTML文件集,现在我正在迁移到MVC应用程序。我试图用提到的代码在博客ASP.NET MVC重定向旧URL到新URL
http://www.bloggersworld.com/index.php/redirecting-old-urls-to-new-in-aspnet-mvc/
重定向旧网址到新的MVC,但得到404错误。
这里是RouteConfig.cs代码
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(new LegacyUrlRoute());
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
我创建了一个类似的类喜欢在博客中提到,并设置重定向提到。从LegacyUrlRoute
new RedirectRule ("oldpage.html", "", "/department/letter/july")
这里部门
示例代码是我的控制器和字母是动作和七月是ID。
如果我直接给这个/部门/信/七月在网址它的作品。
我注意到问题出在URL中的.html而不是.aspx。
如果我给的网址为localhost/oldpage.aspx然后它工作正常,但如果我给本地主机/ oldpage.html它进入404
能否请您指点?