我有一个 asp.net FileUpload 控件。 我可以成功上传文件以存储在 session 中,但是当我试图获取它的输入流时 (我将文件存储在 HttpPosterFile 中)我收到错误
Cannot access a closed file
tr.PostedFile //<== HttpPostedFile;
byte[] byteArray = null;
using (var binaryReader = new BinaryReader(tr.PostedFile.InputStream))
{
byteArray = binaryReader.ReadBytes(tr.PostedFile.ContentLength);
}
最佳答案
将此添加到您的 web.config 文件
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="15360" requestLengthDiskThreshold="15360"/>
</system.web>
http://sanjaysainitech.blogspot.com/2008/12/file-upload-error-can-not-access-closed.html
关于c# - 从 session 获取文件时获取 "Cannot access a closed file"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20468005/