c# - 从 session 获取文件时获取 "Cannot access a closed file"错误消息

标签 c# asp.net file-upload httppostedfile

我有一个 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/

相关文章:

java - 使用 FileItemStream 在 Java 中处理二进制文件

c# - C# 中有类似 PHP 的可选参数吗?

c# - 如何在 mongodb .net 驱动程序中将元素插入数组

c# - MSB0001 : Internal MSBuild Error: refCount should not be less than 1

asp.net - 从 html 按钮控件调用服务器端事件

c# - IIS 7.5 - Windows Server 2008 - 文件上传 405 错误。代码在 windows 2003 服务器中工作

c# - 如何在 Avalonia 表单中强制键盘输入焦点

c# - 将数据从 Html.Action 传递到局部 View

asp.net - 使用 jQuery 将跨域 JSON 发布到 ASP.NET

curl - 如何使用golang代码上传文件