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

发布于 2024-07-09 05:52:16 字数 686 浏览 4 评论 0原文

我正在使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦纸 2024-07-16 05:52:16

您不需要引用 ASP.NET MVC。 您可以使用 StopRoutingHandler 来实现 IRouteHandler ,例如so:

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

这是 .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:

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

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.

美羊羊 2024-07-16 05:52:16

这是一个老问题,但如果它仍然对任何人有帮助,这对我有用:

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

“Ignore”方法存在,而在标准 ASP.NET 中,“IgnoreRoute”方法似乎不存在(即不使用 MVC)。 这将实现与 Haacked 的代码相同的结果,但稍微干净一些......

An old question but in case it still helps anyone, this worked for me:

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

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 ...

花期渐远 2024-07-16 05:52:16

我想补充一点,您还需要确保 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.

娇妻 2024-07-16 05:52:16

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

MapRoute and IgnoreRoute are extension methods in System.Web.Mvc --- do you have that assembly referenced properly?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文