Search code examples
asp.net-mvchtmliis-7http-status-code-404fileapi

IIS7 using HTML5 File API returns 404 for big files


I'm trying to implement File API for image uploading following this example

http://robertnyman.com/html5/fileapi-upload/fileapi-upload.html

On the server side I'm using ASP.NET MVC 3 with IIS7 (integrated, 32 bit only)

Everything works fine locally with Development Server and IIS7.5. On the server it also works, except that if a file is of a certain size (working with a 2.2MB image file) the upload seems to be working but the response is a 404 page. I've configured the maxRequestLength to be 10MB, but even with the default 4MB it should have worked.

The 404 page I get back is the IIS7 by default 404, not my application's 404 page (by looking at the result in Fiddler or Firebug). I'm catching all random URLs and displaying a custom 404 page, but in this case it seems like the request is not sent to the ASP.NET pipeline (the Application Pool is set to Integrated).

I'm also logging any exception that may occur (including 404s) -- the log is clear as far as this problem. There's nothing in the server's event log either.

Any ideas?

Thanks!


Solution

  • It had nothing to do with HTML5 File API or ASP.NET MVC.

    The problem was that in IIS7 you have to specify the maxAllowedContentLength. The advertised default value is 4MB, but this doesn't seem to be the case since uploading a 2MB file failed. Interestingly, the local IIS7.5 (Windows 7) doesn't seem to have this problem -- maybe it's fixed in IIS7.5 (Windows Server 2008 R2)

    To fix it, in your web.config make sure you have something like this:

    <system.webServer>
      ...
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="10485760" />
        </requestFiltering>
      </security>
      ...
    </system.webServer>
    

    The value is in bytes; I specified 10MB