如何忽略asp.net中的路由表单url路由

我正在使用.NET 3.5 SP1框架,并在我的应用程序中实现了URL路由。 我收到了javascript错误:

Error: ASP.NET Ajax client-side framework failed to load.
Resource interpreted as script but transferred with MIME type text/html.
ReferenceError: Can't find variable: Sys

我相信这是因为我的路由选择了微软的axd文件而没有正确发送javascript。 我做了一些研究,发现我可以使用Routes.IgnoreRoute ,这应该允许我忽略下面的Routes.IgnoreRoute

 Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

但是,当我将该行添加到我的Global.asax时,我收到此错误:

CS1061: 'System.Web.Routing.RouteCollection' does not contain a definition for 'IgnoreRoute' and no extension method 'IgnoreRoute' accepting a first argument of type 'System.Web.Routing.RouteCollection' could be found (are you missing a using directive or an assembly reference?)

我已经导入了System.Web.Routing命名空间,有什么想法吗?

您不需要引用ASP.NET MVC。 您可以使用实现IRouteHandler的StopRoutingHandler ,如下所示:

 routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler())); 

这是.NET 3.5 SP1的一部分,不需要MVC。 IgnoreRoutes方法是一种便捷扩展方法,它是ASP.NET MVC的一部分。

一个老问题,但万一它仍然可以帮助任何人,这对我有用:

 routes.Ignore("{resource}.axd/{*pathInfo}"); 

存在“忽略”方法,而在标准ASP.NET中,“IgnoreRoute”方法似乎不显示(即,不使用MVC)。 这将获得与Haacked代码相同的结果,但稍微清晰一点……

我只想补充一点,你还需要确保IgnoreRoutes规则的顺序是正确的顺序,否则你的第一条路线将首先应用,你的IgnoreRoute将被忽略。

MapRoute和IgnoreRoute是System.Web.Mvc中的扩展方法—您是否正确引用了该程序集?