Peeticus Peeticus - 1 year ago 53
ASP.NET (C#) Question

ASP.Net Web Service: Prevent .tmp and .post files for large-ish POSTs

I have a c# .Net 4.5 SOAP web service hosted in IIS 8.5. As this service takes hits I've seen it constantly writing .tmp and .post files to this directory

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\webservices_itcrateengine\2c7c6f10\8cbc7b94\uploads.


I have seen advice on the Interwebs detailing how to move the temp directory elsewhere via the tag's tempDirectory attribute in
web.config
.

I've also seen a general piece of advice that at around ~250k upload size is when ASP.Net will write these .tmp and .post files, but what I really want to know is how can I specify a size at which asp.net buffers upload data to disk via .tmp and .post files?

We have a lot of POSTs to this webservice throughout the day, thousands an hour, ranging in size from 1k-1mb. These machines have plenty of memory so if I can change the threshold .Net uses for buffering to disk, I expect a much lighter load on the physical disks for what I deem unnecessary IO.

Does anybody know how to set an upload size threshold which ASP.Net will use to determine whether to create these temporary .post and .tmp files? Thanks for your time.

Answer Source

Asp.net File Upload uses HttpPostedFile to save the file from the stream.From the msdn documentation

Files are uploaded in MIME multipart/form-data format. By default, all requests, including form fields and uploaded files, larger than 256 KB are buffered to disk, rather than held in server memory.

also regarding the buffer

The amount of data that is buffered in server memory for a request, which includes file uploads, can be specified by accessing the RequestLengthDiskThreshold property or by setting the requestLengthDiskThreshold attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file.

By adjusting the MaxRequestLength and RequestLengthDiskThreshold properties, you can fine tune the performance of your server

So you can have a higher setting in your web.config e.g. 1024 Kb

<httpRuntime requestLengthDiskThreshold = "1024" 

Specifies the limit for the input stream buffering threshold, in kilobytes. Also This value should not exceed the maxRequestLength attribute.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download