IgnoreRoute with webservice - 从路由中排除 asmx URL

发布于 2024-10-12 04:53:40 字数 522 浏览 5 评论 0 原文

我将 filevistacontrol 添加到我的 asp.net MVC Web 应用程序中。

我有一个在路由中被忽略的 media.aspx 页面,

routes.IgnoreRoute("media.aspx");

它成功运行并提供标准的 Web 表单页面。

添加 filevistacontrol 后,我似乎无法忽略该控件对其 Web 服务进行的任何调用。

例如,以下ignoreRoute似乎仍然被MvcHandler拾取。

routes.IgnoreRoute("FileVistaControl/filevista.asmx/GetLanguageFile/");

抛出的异常是:

'The RouteData must contain an item named 'controller' with a non-empty string value'

提前致谢。

Im adding the filevistacontrol to my asp.net MVC web application.

I have a media.aspx page that is ignored in the routing with

routes.IgnoreRoute("media.aspx");

This works successfully and serves a standard webforms page.

Upon adding the filevistacontrol, I can't seem to ignore any calls the control makes to it's webservice.

Eg the following ignoreRoute still seems to get picked up by the MvcHandler.

routes.IgnoreRoute("FileVistaControl/filevista.asmx/GetLanguageFile/");

The exception thrown is:

'The RouteData must contain an item named 'controller' with a non-empty string value'

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

国际总奸 2024-10-19 04:53:40

简短回答:

routes.IgnoreRoute( "{*url}", new { url = @".*\.asmx(/.*)?" } );

详细回答:

如果您的服务可以位于路径的任何级别,这些选项都不适用于所有可能的 .asmx 服务

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");

默认情况下,路由模式中的参数将匹配,直到他们找到了一条斜线。

如果参数以星号 * 开头(如这些答案中的 pathInfo),它将匹配所有内容,包括斜杠。

因此:

  • 第一个答案仅适用于根路径中的 .asmx 服务,因为 {resource} 不会匹配斜杠。 (适用于诸如 http://example.com/weather.asmx/forecast 之类的东西)
  • 第二个仅适用于与 .asmx 服务相距一级的服务root.{directory} 将匹配路径的第一段,{resource} 将匹配服务的名称。 (适用于诸如http://example.com/services/weather.asmx/forecast之类的东西)

没有一个适用于http://example.com/services/weather/weather。 asmx/forecast

解决方案是使用 IgnoreRoute 方法的另一个重载,该方法允许指定约束。使用此解决方案,您可以使用匹配所有 url 的简单模式,如下所示:{*url}。然后您只需设置一个约束来检查此 url 是否引用 .asmx 服务。此约束可以用如下正则表达式表示:.*\.asmx(/.*)?。此正则表达式匹配以 .asmx 结尾的任何字符串,可选地后跟斜杠及其后的任意数量的字符。

所以,最终的答案是这样的:

routes.IgnoreRoute( "{*url}", new { url = @".*\.asmx(/.*)?" } );

Short answer:

routes.IgnoreRoute( "{*url}", new { url = @".*\.asmx(/.*)?" } );

Long answer:

If your service can be in any level of a path, none of these options will work for all possible .asmx services:

routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");

By default, the parameters in a route pattern will match until they find a slash.

If the parameter starts with a star *, like pathInfo in those answers, it will match everything, including slashes.

So:

  • the first answer will only work for .asmx services in the root path, becasuse {resource} will not match slashes. (Would work for something like http://example.com/weather.asmx/forecast)
  • the second one will only work for .asmx services which are one level away from the root.{directory} will match the first segment of the path, and {resource} the name of the service. (Would work for something like http://example.com/services/weather.asmx/forecast)

None would work for http://example.com/services/weather/weather.asmx/forecast)

The solution is using another overload of the IgnoreRoute method which allows to specify constraints. Using this solution you can use a simple pattern which matches all the url, like this: {*url}. Then you only have to set a constraint which checks that this url refers to a .asmx service. This constraint can be expressed with a regex like this: .*\.asmx(/.*)?. This regex matches any string which ends with .asmx optionally followed by an slash and any number of characters after it.

So, the final answer is this:

routes.IgnoreRoute( "{*url}", new { url = @".*\.asmx(/.*)?" } );
埋情葬爱 2024-10-19 04:53:40

我使用这个(其他答案的组合)让它工作:

routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");

I got it to work using this (a combo of other answers):

routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");
半世蒼涼 2024-10-19 04:53:40

使用时会发生什么:

routes.IgnoreRoute("FileVistaControl/filevista.asmx");

如果这不起作用,请尝试使用 ASP.NET 路由调试器来帮助您:
http://haacked.com/archive/2008/03/13 /url-routing-debugger.aspx

What happens when you use:

routes.IgnoreRoute("FileVistaControl/filevista.asmx");

If that doesn't work, try using the ASP.NET Routing Debugger to help you:
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

浅沫记忆 2024-10-19 04:53:40

试试这个:

routes.IgnoreRoute("{*filevista}", new { filevista = @"(.*/)?filevista.asmx(/.*)?" }); 

这是基于 Phil Haack 的建议 此处

Try this:

routes.IgnoreRoute("{*filevista}", new { filevista = @"(.*/)?filevista.asmx(/.*)?" }); 

This is based on a Phil Haack recommendation stated here.

简单爱 2024-10-19 04:53:40

你有没有尝试过:

routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

Have you tried:

routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
流年已逝 2024-10-19 04:53:40

如果您发布路由配置的源代码,将会有所帮助。我将在黑暗中进行尝试并确保您的 IgnoreRoute() 调用全部位于路由定义的顶部。

IgnoreRoute 的工作方式是创建一个与忽略的路由 URL 和约束相匹配的路由,并附加一个 StopRoutingHandler 作为 RouteHandler。 UrlRoutingModule 知道 StopRoutingHandler 意味着它不应该路由请求。

众所周知,路由按照定义的顺序进行匹配。因此,如果您的 {controller}/{action}/{id} 路由出现在 "FileVistaControl/filevista.asmx/GetLanguageFile/" 路由之前,那么它将与“{controller}/{action}/{id}” 路线。

我可能完全没有根据,但如果不看到你的消息来源就很难知道。希望这有帮助。并贴出源码!你会得到更好的答案。

It would help if you posted the source for your route configuration. I'm going to take a shot in the dark and say to make sure that your IgnoreRoute() calls are all at the top of your routing definition.

The way IgnoreRoute works is to create a route that matches the ignored route URL and constraints, and attaches a StopRoutingHandler as the RouteHandler. The UrlRoutingModule knows that a StopRoutingHandler means it shouldn't route the request.

As we know, the routes are matched in the order of which they are defined. So, if your {controller}/{action}/{id} route appears before your "FileVistaControl/filevista.asmx/GetLanguageFile/" route, then it will match the "{controller}/{action}/{id}" route.

I may be totally off base here, but it's hard to know without seeing your source. Hope this helps. And post source code! You'll get better answers.

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