简体   繁体   中英

asp.net mvc c# Request.Files[0].ContentLength getting zero internet explorer

The file size validation is not working in Internet Explorer, it worked fine in FireFox. It is posting at octet in Internet Explorer, what could be the reason?

Session["ContentLength"] = (Request.Files[0].ContentLength / 1024);
Session["ContentType"] = Request.Files[0].ContentType;
byte[] b = new byte[Request.Files[0].ContentLength];
Request.Files[0].InputStream.Read(b, 0, Request.Files[0].ContentLength);
Session["ContentStream"] = b;
return Content(Request.Files[0].ContentType + ";" + Request.Files[0].ContentLength / 1024);

While maintaining a legacy asp application which included a file upload module, I encountered a peculiar error where every once in a while, a user's upload would be rejected (we filtered on mime type so that only certain file types were allowed) even though it was a valid file type.

The issue turned out to be an oddity with Microsoft Office Applications. If the user tried to upload an office file while it was open in its respective software (eg: .doc file open in Word), the mime-type would be incorrectly reported as Octet-Stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM