Chris Eldredge
Chris Eldredge

Reputation: 2951

SystemWeb Host: IAppBuilder.UseWebApi ignores paths with extensions

I have an Owin Startup class that registers a WebApi controller action and hooks it in using IAppBuilder.UseWebApi. My route templates is /api/packages/{id}/{version} where version may contain periods (as in 1.0.0).

This works fine with self hosting, but when I try to run my code in IIS using Microsoft.Owin.Host.SystemWeb, something is preventing my action from being invoked when the path looks like a static content request.

For example, GET /api/packages/Foo/1.0 works on self host but results in a 404 on IIS.

If I add a trailing slash as in GET /api/packages/Foo/1.0/ it works in both self host and IIS.

It seems that something in the UseWebApi method is preventing Web Api from handling requests that look like files with extensions.

Other Owin middleware sees all of these requests, so I know the request is getting into the Owin pipeline, but then something about the UseWebApi method seems to be ignoring some requests.

Related: Owin Middleware results in 404 on server, Owin hosted on IIS doesn't capture URLs with Dot "."

Upvotes: 3

Views: 2767

Answers (1)

Chris Eldredge
Chris Eldredge

Reputation: 2951

After further debugging, I was mapping another OWIN middleware for SignalR before wiring in WebApi, and the order seems to matter on Web-Host but not on Self-Host. Changing the order resolved this issue for me.

Update: When using Owin.Host.SystemWeb, IAppBuilder.UseStageMarker(PipelineStage.MapHandler) should be invoked after any middleware that wish to handle requests that appear to be for static content.

See https://katanaproject.codeplex.com/wikipage?title=Static%20Files%20on%20IIS and http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline.

Upvotes: 0

Related Questions