如何忽略asp.net路线形成URL路由 [英] How to ignore route in asp.net forms url routing

查看:176
本文介绍了如何忽略asp.net路线形成URL路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是.NET 3.5 SP1框架,我实现了网址在我的应用程序的路由。我是越来越JavaScript错误:

I am using the .NET 3.5 SP1 framework and I've implemented URL routing in my application. I was getting javascript errors:


错误:ASP.NET AJAX客户端框架未能加载结果。
资源间preTED为脚本,但使用MIME类型text / html转移。结果
的ReferenceError:找不到变量:SYS

我相信这是因为我的路由拿起微​​软AXD文件,而不是正确地传送下来的JavaScript。我做了一些研究,发现我可以用 Routes.IgnoreRoute ,这应该让我忽略像下面的AXD:

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}");

但是,当我加入这行到我的Global.asax中我得到这个错误:

But, when I add that line to my Global.asax I get this error:


CS1061:'System.Web.Routing.RouteCollection'不包含'IgnoreRoute',没有扩展方法'IgnoreRoute接受型System.Web.Routing.RouteCollection'的第一个参数的定义可以找到(是否缺少使用指令或程序集引用?)

我已经得到了引进的 System.Web.Routing 命名空间,任何想法?

I've got the System.Web.Routing namespace imported, any ideas?

推荐答案

您不必引用ASP.NET MVC。您可以使用StopRoutingHandler它实现IRouteHandler像这样:

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()));

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

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.

这篇关于如何忽略asp.net路线形成URL路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆