IIS intercepting WebApi call

Topics: Web Api
Jan 9, 2012 at 4:49 PM
Edited Jan 9, 2012 at 11:08 PM

Hi,

I have a WebApi service that is designed to upload a file via a POST message and the url would look something like http://website:port/api/files/file.png which works fine when I run against cassini but when I run the same thing against IIS my web api isn't called and I get a 404.  What I believe is happening is that IIS is seeing the URL and assuming that it should be mapped to a file that is on the server itself. 

Here is the route that I have set up:

RouteTable.Routes.Add(new ServiceRoute("api/files", this.apiFactory, typeof(FilesService)));

Here is the WebApi method signature:

[WebInvoke(UriTemplate = "{filename}", Method = "POST")]
public HttpResponseMessage Upload(string filename, HttpRequestMessage request)

What is the trick to getting IIS to ignore the url and just pass it down to the routing system?

Cheers,

Clint

Jan 9, 2012 at 10:38 PM

What OS (aka, what version of IIS)?

Jan 9, 2012 at 11:07 PM

Windows Server 2008 R2 (IIS 7.5)

Jan 10, 2012 at 12:14 PM

Have you tried this?

RouteTable.Routes.RouteExistingFiles = true;

Jan 10, 2012 at 11:24 PM

I just tried it but it didn't make any difference.

At the moment I am just replacing the . with a ~ at the client and then switch it back when I hit the server.  Though I am hoping this will be temporary.

Jan 11, 2012 at 6:41 PM

Why isn't "filename" a part of the request body that's being posted to "/api/files"?

Jan 12, 2012 at 6:15 PM

Mostly because I want the GET and POST methods to seem natural and consistent.

i.e. GET /api/files/filename.png would return the file.

While I realize there are work arounds I would prefer to make it do what I want if that is at all possible.

Jan 12, 2012 at 6:57 PM
Edited Jan 12, 2012 at 6:59 PM

-del wrong subject-