gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:55:21 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com