如何忽略 ASP.NET MVC 路由中的特定路由

How to ignore a specific route in ASP.NET MVC routing

如果我希望应用程序忽略所有以单词 "score" 喜欢

http://myserver/score*.*

?

换句话说,任何以文本 "score" 开头的 url 我希望我的应用忽略。

我试过了:

routes.IgnoreRoute("score*.*/{*pathInfo}");

我还尝试了此语法的其他几种组合,但不太正确。

这是我目前在 RouteConfig 中的内容。这几乎是标准的东西。

 public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Order", action = "Add", id = UrlParameter.Optional }
        );
    }
}

您应该将分数*.* 作为正则表达式放在 IgnoreRoute 中:

routes.IgnoreRoute("{score}/{*pathInfo}", new { score = @"score*.*" });

对于更一般的答案,您可以使用此模式忽略您想要的路由:

Routes.IgnoreRoute("{*foo*}", new { foo = @"someregextoignorewhatyouwant"});

因此,对于 score.js 和 score.txt 路由,您将添加过滤该路由的正则表达式。