我有一个 angularJS 应用程序。我创建了一个 Controller /操作,可根据任何请求返回呈现的 index.cshtml。这是我唯一的 mvc4 Controller 。我将 webapi 用于所有其他行为。客户端应该只处理路由。目前运行良好。
RouteExistingFiles = false;
routes.MapRoute(
name: "Default",
url: "{*url}",
defaults: new { controller = "Index", action = "Index" }
);
问题在于此解决方案匹配“localhost/favicon.ico、localhost/template.html”等资源。 我可以阻止或忽略所有这样的请求吗?
最佳答案
你可以使用 IgnoreRoute
所以路由模块会忽略对这些资源的请求,例如:
routes.IgnoreRoute("favicon.ico");
routes.IgnoreRoute("{templateName}.html");
这些必须添加到您当前的 Default
路由之前。
关于c# - MVC 路由匹配除资源之外的所有路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459793/