Accessing to Request object will lead to ReadEntityBody to return 0 (in a HttpHandler class)
I created a httpHandler that successfully implements IHttpHandler for handling file uploads. It works perfectly fine. You send the file with the form, the class receives it and will save it to hard disk. It reads chunks of file with ReadEntityBody function of HttpWorkerRequest class.
Here is the situation i'm faced with.If at any stage before trying to read the file with ReadEntityBody, I try to access Request object (even Request.InputStream.Length!) ReadEntityBody would return 0 means it won't read from file stream.
After further testing I found out the reason behind it. Accessing to Context.Current.Request
object will trigger some sort of functionality that will cause asp.net to handle file uploads at that m开发者_如何学Gooment by it's own! I believe this is a bug.
for example exactly after this line of code, asp.net will upload the file completely, and so there will be no stream for ReadEntityBody to read from later.
int FileSize = context.Request.InputStream.Length;
Can anybody tell how to stop this?
It wont "upload" the file. The file is already uploaded regardless. The way I understand it is that Accessing Request object will cause it to read out request data into Request.Form
, Request.Files
, etc.
Obvious thing to try would be to set Request.InputStream.Position = 0
before calling your chunked read methods.
精彩评论