tags:

views:

124

answers:

1

I have a web service on which the end users will be uploading ZIP archives that can be very large (one test file is over 200MB). I'd like to handle oversized files proactively and size-limited upload failures gracefully.

Since the web app will be deployed on customers' machines, so I cannot easily ensure that the configuration matches any fixed size. I've documented how to use the appcmd command for them to set the requestLimits.maxAllowedContentLength value beyond the 30MB default.

But I'd like to handle it in the web app; I'm hoping for two things:

  1. To show the current limit on the page where they initiate the file upload, something along the lines of:

    Each file upload is limited to 15MB. If your archive is larger, (etc., etc., etc.)

  2. To give a meaningful error when that size is exceeded. Currently, it takes a long time for the data to be sent, and then I see a misleading 404 page.

Any thoughts?

[Edit]

http://www.developer.com/db/article.php/10920_3426051_2/Limiting-Upload-Sizes-with-ASPNET.htm

I found the above article -- but while I can intercept the error I keep getting a connection reset in the browser on Request.Redirect() or Context.RewritePath() so it's really no better than the 404. Hmmm, actually that's with VS2008's debug server, not with IIS.

+1  A: 

To get the masxAllowed content you can use this

protected int GetMaxUploadSize()
{
    System.Web.Configuration.HttpRuntimeSection httpRuntimeSec = (System.Web.Configuration.HttpRuntimeSection)ConfigurationManager.GetSection("system.web/httpRuntime");  
    if (httpRuntimeSec != null)  
    {  
       return httpRuntimeSec.MaxRequestLength;  
    }  
    else
    {
       return 0;
    }
}

Also add this to your web.config:

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

For your 2nd question i will suggest using a client side app so you can validate the file size before uploading, one option could be silverlight

alejandrobog
Thanks, but that's the "web.config" setting, over which I have control (and I've set to 128MB) unless they change it. I'm looking for the IIS setting, which defaults to 30MB.
NVRAM
I read that in order to avoid IIS block you can add this to your web.cofig (have´t try it)<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="1000000" /> </requestFiltering> </security></system.webServer>
alejandrobog
Thanks, but as I mentioned I have this set to ~128MB already. There's an IIS limit that defaults to 30MB and that is what I want to read.
NVRAM