我刚学与路由工作ASP.NET MVC和我试图了解IgnoreRoute方法。
我试图阻止用户访问"Content/{filename}.html"
。 我已经把这个作为我的RegisterRoutes方法中的第一个电话。 这里是我的代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("Content/{filename}.html");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "^.*", action = "^Index$|^About$" },
new[] { "UrlsAndRoutes.AditionalControllers" });
routes.MapRoute("MyRoute2", "{controller}/{action}/{id}/{*catchall}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "^.*", action = "^Index$|^About$" },
new[] { "UrlsAndRoutes.Controllers" });
routes.MapRoute("ShopSchema2", "Shop/OldAction", new { controller = "Home", action = "Index" });
routes.MapRoute("ShopSchema", "Shop/{action}", new { controller = "Home" });
routes.MapRoute("", "X{controller}/{action}");
routes.MapRoute(
name: "",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
}
如果我尝试访问本地主机一样的链接:53907 /内容/ Static.html,它不应该让我来显示从到目前为止我所了解的文件,但它确实显示它。
我究竟做错了什么?