我刚刚学习在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" }
);
}
如果我尝试访问 localhost:53907/Content/Static.html 之类的链接,它不应该允许我根据我目前所了解的内容显示该文件,但它确实会显示它。
我究竟做错了什么?