开发者

Accessing to Request object will lead to ReadEntityBody to return 0 (in a HttpHandler class)

开发者 https://www.devze.com 2023-02-01 17:44 出处:网络
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 di

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号