POST to .apk on IIS returns HTTP 200, no download. Using StaticFileModule and correct MIME type

StackOverflow https://stackoverflow.com/questions/22167710

  •  01-06-2023
  •  | 
  •  

Question

Which IIS module do I use to download a binary file to a client?

I have an inherited application which I can't modify, it tries to download an APK file to an Android device.

The app does a POST request to IIS 7, which I have configured with the MIME type for APK files. I tried both "application/octet-stream" and "application/vnd.android.package-archive". Both mime types work if I try a GET request.

Now for the fun part: to accept POST-verb requests to .apk extensions, I created a module mapping for StaticFileModule. The mapping is not limited to files or directories, accepts POST and GET verbs, and requires Read access.

I assumed that StaticFileModule would allow requests to any type of file and IIS would return the file without processing - it turns out that this is not true.

StaticFileModule does not return the file, it just accepts the requests and returns status 200. GET and POST do the same thing. If I disable the module for GET requests, IIS uses a different module and the download works for GET. If I disable POST however, the download doesn't work (and the module doesn't activate), and I get a 405 "HTTP verb used to access this page is not allowed" instead.

Why won't the default StaticFile handler mapping (*) allow POST when it accepts "All verbs" - and it has no problem with the GET request - yet when I define my own handler, it doesn't send anything back for either verb?


I want to add that if I change the module mapping to invoke handler only if request is mapped to file, folder, or file or folder, the module mapping does not seem to apply to my request. This doesn't make sense to me. I am using URL rewriting, but only if {REQUEST_FILENAME} is not a file, and is not a directory. Rewriting does not apply (it rewrites to index.php so I'd know if it did).

Was it helpful?

Solution

I ended up writing my own managed handler because I have not found a working solution on the web.

definitions did not help StaticFileModule to serve APK files, and writing my own handler proved to be extremely easy to do using the excellent guide here: http://www.iis.net/learn/develop/runtime-extensibility/developing-iis-modules-and-handlers-with-the-net-framework

Inside the handler, I check to see if the file exists, create a stream, write the stream to response.OutputStream and that's all there is to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top