views:

481

answers:

1

Is there any way (probably a module) that can make IIS7 rejects a post with a file larger than 10mb?

My ASP.NET application has an upload page, and the file cannot be larger than 10mb, I believe that I can check the size of the file only after everything was already sent to the server.

An IIS7 module would be the right choice for this, anyone knows about one?

+6  A: 

You can set the limit in the Web.Config

<system.web>
  <httpRuntime  maxRequestLength="xxxxx" executionTimeout="xx"/>
</system.web>

sidenote:

IIS7 will reject any file larger then 30 meg by default you can increase this by adding the following code

<security>
 <requestFiltering>
  <requestLimits maxAllowedContentLength=”XXXXXX″ />
 </requestFiltering>
</security>

If you are looking to get the content size before an upload you should be able to use the HTTP method HEAD to retrieve Content-Length.

Implementation

cgreeno
but will it avoid the file to be uploaded first and then the size checked? i.e. throws an exception right after the headers are sent?
Bruno
@Bruno, it will cut off the request at 10MB, and throw an error if over. However there is nothing that will check the file before upload. There are some flash uploaders that do this, but it is probably not what you want.
Nick Berardi
There is a PHP recommendation for asking the browser not to upload files over a specified limit, but IMHO no browsers implement it.
DrJokepu