ASP.NET Routing - Ignore routes for files with specific extension, regardless of directory

后端 未结 2 562
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 16:39

Say I want to remove any mapped routes for files with a certain file extension.

 RouteTable.Routes.Ignore(\"{root}.hello\");

Works for any

2条回答
  •  甜味超标
    2020-12-16 17:13

    If you're using ASP.NET MVC, use IgnoreRoutes (MVC Extension method)

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

    If you're using ASP.NET Web Forms, use StopRoutingHandler which implements IRouteHandler.

    routes.Add(new Route("*someregextoignorewhatyouwant*", new StopRoutingHandler()));
    

提交回复
热议问题