c# - MVC 路由匹配除资源之外的所有路由

标签 c# asp.net-mvc asp.net-mvc-4

我有一个 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/

相关文章:

asp.net-mvc - ASP.NET MVC : Stack overflow error when calling Html. 渲染部分()

asp.net-mvc - 如何使代码缩进在 vbhtml razor 文件中正确运行?

javascript - 将 glyphicon 从 bootstrap 3 添加到 html helper textboxfor

asp.net-mvc - 使用 MVVM 将 kendo.data.DataSource 绑定(bind)到组合

asp.net-mvc - 在 Asp.Net MVC 网站中维护状态

c# - 动态更改 ASP.NET MVC 中的样式属性

C# Excel 数据导出而不打开 Excel 文档

c# - Unity 容器调用非默认 ctor

asp.net-mvc-4 - Team Foundation Server - 提交的文件对于其他 TFS 成员来说是隐藏的

c# - 标签控件上的键盘助记符的用途是什么?