IgnoreRoute with webservice - Exclude asmx URLs from routing

前端 未结 6 519
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 08:48

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(\"m         


        
相关标签:
6条回答
  • 2020-12-30 09:26

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

    routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");
    
    0 讨论(0)
  • 2020-12-30 09:29

    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

    0 讨论(0)
  • 2020-12-30 09:39

    Have you tried:

    routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
    routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");
    
    0 讨论(0)
  • 2020-12-30 09:43

    Try this:

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

    This is based on a Phil Haack recommendation stated here.

    0 讨论(0)
  • 2020-12-30 09:46

    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(/.*)?" } );
    
    0 讨论(0)
  • 2020-12-30 09:47

    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.

    0 讨论(0)
提交回复
热议问题