获取“无法访问关闭的文件"从会话获取文件时出现错误消息 [英] Getting "Cannot access a closed file" errormessage when getting file from session

查看:136
本文介绍了获取“无法访问关闭的文件"从会话获取文件时出现错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net FileUpload控件. 我可以成功上传文件以存储在会话中,但是当我尝试获取其输入流时 (我将文件存储在HttpPosterFile中)遇到错误

I have a asp.net FileUpload control. I can successfully upload file to store in session, but when I am tring to get its inputstream (I'm store file in HttpPosterFile) I'm getting error

无法访问已关闭的文件

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文件

add this to your web.config file

<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

这篇关于获取“无法访问关闭的文件"从会话获取文件时出现错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆