如何忽略asp.net表单中的url路由
我正在使用 .NET 3.5 SP1 框架,并在我的应用程序中实现了 URL 路由。 我收到 javascript 错误:
错误:ASP.NET Ajax 客户端框架加载失败。
资源解释为脚本,但以 MIME 类型 text/html 传输。
ReferenceError:找不到变量:Sys
我认为这是因为我的路由正在获取 microsoft axd 文件,而没有正确发送 javascript。 我做了一些研究,发现我可以使用 Routes.IgnoreRoute
,这应该允许我忽略 axd,如下所示:
Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
但是,当我将该行添加到 Global.asax 时,我收到此错误:
<代码> CS1061:“System.Web.Routing.RouteCollection”不包含“IgnoreRoute”的定义,并且找不到接受“System.Web.Routing.RouteCollection”类型的第一个参数的扩展方法“IgnoreRoute”(您是否缺少使用指令还是程序集引用?)
我已经导入了 System.Web.Routing
命名空间,有什么想法吗?
I am using the .NET 3.5 SP1 framework and I've implemented URL routing in my application. I was getting javascript errors:
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
Which I believe is because my routing is picking up the microsoft axd files and not properly sending down the javascript. I did some research and found that I could use Routes.IgnoreRoute
, which should allow me to ignore the axd like below:
Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
But, when I add that line to my Global.asax I get this error:
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?)
I've got the System.Web.Routing
namespace imported, any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不需要引用 ASP.NET MVC。 您可以使用 StopRoutingHandler 来实现 IRouteHandler ,例如so:
这是 .NET 3.5 SP1 的一部分,不需要 MVC。 IgnoreRoutes 方法是一种方便的扩展方法,它是 ASP.NET MVC 的一部分。
You don't need to reference ASP.NET MVC. You can use the StopRoutingHandler which implements IRouteHandler like so:
This is part of .NET 3.5 SP1 and doesn't require MVC. The IgnoreRoutes method is a convenience extension method which is part of ASP.NET MVC.
这是一个老问题,但如果它仍然对任何人有帮助,这对我有用:
“Ignore”方法存在,而在标准 ASP.NET 中,“IgnoreRoute”方法似乎不存在(即不使用 MVC)。 这将实现与 Haacked 的代码相同的结果,但稍微干净一些......
An old question but in case it still helps anyone, this worked for me:
The "Ignore" method exists, whereas in standard ASP.NET the "IgnoreRoute" method appears not to (i.e., not using MVC). This will achieve the same result as Haacked's code, but is slightly cleaner ...
我想补充一点,您还需要确保 IgnoreRoutes 规则的顺序正确,否则您的第一条路线将首先应用,并且您的 IgnoreRoute 将...将被忽略。
I would just like to add that you also need to make sure the order of your IgnoreRoutes rule is in the the correct order otherwise your first route will be applied first and your IgnoreRoute will... well be ignored.
MapRoute 和 IgnoreRoute 是 System.Web.Mvc 中的扩展方法 --- 您是否正确引用了该程序集?
MapRoute and IgnoreRoute are extension methods in System.Web.Mvc --- do you have that assembly referenced properly?