0

I have an endpoint that I want to catch all POSTs regardless of what the url is.

Currently I have:

public class ProxyController : ApiController
    {
        [Route("{*url}")]
        [HttpPost]
        public async Task<HttpResponseMessage> Post()
        {
             .............

This works great for urls like 'http://localhost:64578/SomeRoute'

and the endpoint gets hit.

But as soon as I add an extension eg.

'http://localhost:64578/SomeRoute.svc'

The endpoint doesn't get hit.

It will however hit 'http://localhost:64578/SomeRoute.svc/'

but I really need the former.

My route setup looks like:

public static void Register(HttpConfiguration config)
        {
            var container = StructureMapIoC.GetStructureMapContainer();
            ConfigStructureMapContainer(config, container);

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }

Is anyone able to explain why and suggest how to fix?

CraftyFox
  • 165
  • 2
  • 11

1 Answers1

0

This should catch all routes with all extensions {*.*}

Edit: Tested some options from ASP.net MVC4 WebApi route with file-name in it.

  • Combination of [Route("{*.*}")] and
<system.webServer>
  <handlers>
    <add name="ManagedFilesExtension" path="*.*" verb="POST" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  </handlers>
</system.webServer>

does work, but not for all extensions (*.svc doesn't work for example)

  • Same for [Route("{*.*}")] +
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

but this option if worse for performance since is catches all request types (first one only catches POST)

maxc137
  • 2,291
  • 3
  • 20
  • 32