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

Ray*_*Ray 5 c# asp.net asp.net-mvc asp.net-mvc-routing asp.net-mvc-4

如果我希望应用程序忽略以"得分"一词开头的所有网址,那么在ASP.NET MVC应用程序中放入RouteConfig.RegisterRoutes方法的正确语法是什么

http://myserver/score*.*

换句话说,任何以文本"得分"开头的网址都希望我的应用忽略.

我试过了:

routes.IgnoreRoute("score*.*/{*pathInfo}");
Run Code Online (Sandbox Code Playgroud)

我也尝试了这种语法的其他几种组合,但不能完全正确.

这是我目前在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 }
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

fre*_*hbm 4

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

routes.IgnoreRoute("{score}/{*pathInfo}", new { score = @"score*.*" });
Run Code Online (Sandbox Code Playgroud)

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

Routes.IgnoreRoute("{*foo*}", new { foo = @"someregextoignorewhatyouwant"});
Run Code Online (Sandbox Code Playgroud)

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