Accessing to Request object will lead to ReadEntityBody to return 0 (in a HttpHandler class)
        Posted  
        
            by 
                EBAG
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by EBAG
        
        
        
        Published on 2010-12-25T05:15:40Z
        Indexed on 
            2010/12/25
            5:54 UTC
        
        
        Read the original article
        Hit count: 212
        
ASP.NET
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 moment 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?
© Stack Overflow or respective owner