Reputation: 10509
A client page uses javascript to post multipart form data (files) to my ASP.NET site (ashx handler).
User selects several files and start a concurrent upload. When files are like 150MB+, this generates several concurrent POST handlers of the ASP.NET server side.
I have the session control implemented, along with captcha functionality to exactly know if it is not a bot flooding my server.
But the problem is with the initial upload start.
Each time a handler is to process a POST
, it checks an ID of the session (my custom session, one per user page), and adds the Request.ContentLength
size to the total size of files POST
ed per session. This data is saved to an XML.
But since several initial posts occur simultaneously, an XML writer that records the sum of bytes "chokes" and reports 0 bytes per session for all initial POST
s, since they come in at the same time.
I've implemented lock
on my persister
object (that does XML-writing), but now until one POST is totally processed, others can't go on.
Also even though I don't do anything with the requests that come in "after the upload limit", they still take time to upload the data to the server.
So my questions are:
What is the correct pattern to process several concurrent POST
uploads?
Is there a way to immediately drop POST as soon as the request is filtered in ASP.NET handler code, and save the client an effort of uploading the data to IIS?
UPDATE: When lock
ing only on XML writing/max session length calculation I still have the concurrency, which is good. Now I only need to figure out how to drop session immediately from ashx handler code.
Upvotes: 6
Views: 1221
Reputation: 299
Is your ashx handler written to execute asynchronously? If not, this a great article for implementing async ashx handlers:
http://msdn.microsoft.com/en-us/magazine/cc163463.aspx
Upvotes: 1