FileUpload大小受requestLengthDiskThreshold限制 [英] FileUpload size limited by requestLengthDiskThreshold

查看:112
本文介绍了FileUpload大小受requestLengthDiskThreshold限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将ASP.NET 1.1应用程序迁移到2.0后,我们得到不能

访问已关闭的文件。上传时出错。我在

主题上发现了一些帖子,然后使用新的FileUpload控件从使用Html文件输入控件转到了



以前,我在machine.config

文件中设置了maxRequestLength属性,以便成功上传100MB。在v2.0应用程序中,我已经向web.config添加了一个httpRuntime节点,并且像以前一样设置了

maxRequestLength = 102400。我还将

requestLengthDiskThreshold值设置为8192.


执行此操作后,可以上载最大为8192KB的文件。我现在发现
发现requestLengthDiskThreshold是限制值。通过这个我

意味着小于requestLengthDiskThreshold的文件将上传

,而大于requestLengthDiskThreshold设置的文件

则抛出b $ b。无法访问已关闭的文件例外。这已经证明是真的

,为阈值输入了许多不同的值。


我的理解是requestLengthDiskThreshold值设置为
$ b在内存中缓存的$ b量的请求,超出此值的数据暂时写入磁盘。它是否正确?为什么我发现我的

文件上传大小受requestLengthDiskThreshold设置的限制?


非常感谢 - phil

After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot
access a closed file" errors when uploading. I found a number of post on
the subject and have since moved from using an Html File Input control to
using the new FileUpload control.

Previously, I had set the maxRequestLength attribute in the machine.config
file to allow 100MB uploads with success. In the v2.0 application I have
added an httpRuntime node to the web.config and have set
maxRequestLength=102400 as before. I also set the
requestLengthDiskThreshold value to 8192.

After doing this, files up to 8192KB in size were uploadable. I have now
found that the requestLengthDiskThreshold is the limiting value. By this I
mean that files that are smaller than the requestLengthDiskThreshold will
upload, while files larger than the requestLengthDiskThreshold setting
throw the "Cannot access a closed file" exception. This has proved true
with a number of different values entered for the threshold.

My understanding is that the requestLengthDiskThreshold value sets the
amount of the request that is cached in memory, and data beyond this value
is temporarily written to disk. Is this correct? Why am I finding that my
file upload size is limited by the requestLengthDiskThreshold setting?

Thanks much -- phil

推荐答案

你对requestLengthDiskThreshold的理解是正确的,这暗示了基础流过早关闭的



出于兴趣,尝试将你的maxrequestlength设置为比预期的最大文件大小要大得多的b $ b,看看问题是否消失。


问候


John Timney(MVP)

" Phil Z." < ph *** @ noemail.noemailwrote in message

新闻:哦************** @ TK2MSFTNGP02.phx.gbl ...
Your understanding of requestLengthDiskThreshold is correct, which suggests
that the underlying stream is being closed prematurely.

Out of interest try setting your maxrequestlength to be significantly larger
than your max file size expected and see if the problem goes away.

Regards

John Timney (MVP)
"Phil Z." <ph***@noemail.noemailwrote in message
news:Oh**************@TK2MSFTNGP02.phx.gbl...

将ASP.NET 1.1应用程序迁移到2.0后,我们得到不能

访问已关闭的文件。上传时出错。我在

主题上发现了一些帖子,然后使用新的FileUpload控件从使用Html文件输入控件转到了



以前,我在machine.config

文件中设置了maxRequestLength属性,以便成功上传100MB。在v2.0应用程序中,我已经向web.config添加了一个httpRuntime节点,并且像以前一样设置了

maxRequestLength = 102400。我还将

requestLengthDiskThreshold值设置为8192.


执行此操作后,可以上载最大为8192KB的文件。我现在发现
发现requestLengthDiskThreshold是限制值。这个

我的意思是小于requestLengthDiskThreshold

的文件将上传,而大于requestLengthDiskThreshold

设置的文件会抛出无法访问已关闭的文件例外。这已经证明是真实的,为阈值输入了许多不同的值。


我的理解是requestLengthDiskThreshold值设置为
$ b在内存中缓存的$ b量的请求,超出此值的数据暂时写入磁盘。它是否正确?为什么我发现

我的文件上传大小受requestLengthDiskThreshold设置的限制?


非常感谢 - phil
After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot
access a closed file" errors when uploading. I found a number of post on
the subject and have since moved from using an Html File Input control to
using the new FileUpload control.

Previously, I had set the maxRequestLength attribute in the machine.config
file to allow 100MB uploads with success. In the v2.0 application I have
added an httpRuntime node to the web.config and have set
maxRequestLength=102400 as before. I also set the
requestLengthDiskThreshold value to 8192.

After doing this, files up to 8192KB in size were uploadable. I have now
found that the requestLengthDiskThreshold is the limiting value. By this
I mean that files that are smaller than the requestLengthDiskThreshold
will upload, while files larger than the requestLengthDiskThreshold
setting throw the "Cannot access a closed file" exception. This has
proved true with a number of different values entered for the threshold.

My understanding is that the requestLengthDiskThreshold value sets the
amount of the request that is cached in memory, and data beyond this value
is temporarily written to disk. Is this correct? Why am I finding that
my file upload size is limited by the requestLengthDiskThreshold setting?

Thanks much -- phil



感谢您的回复。我将maxRequestLength设置为100MB(102400)

并且遇到了3个不同文件的这种行为,一个大约6MB,

一个大约10MB,一个大约一个45MB,都远低于100MB

maxRequestLength。在每种情况下,如果requestLengthDiskThreshold被设置为

小于它失败的文件大小,并且如果它超过文件大小则

成功。


这让我想知道工作进程是否无法保存到磁盘上,因为某些原因......我在一次测试中运行了filemon并且没有发现任何问题。

" John Timney(MVP)" < x _ **** @ timney.eclipse.co.ukwrote in message

news:rt ********************** ********@eclipse.net。 uk ...
Thanks for the response. I have the maxRequestLength set to 100MB (102400)
and have experienced this behavior with 3 different files, one at about 6MB,
one at about 10MB, and one at about 45MB, all well less than the 100MB
maxRequestLength. In each case if the requestLengthDiskThreshold is set to
less than the file size it fails, and if it''s more than the file size it
succeeds.

It makes me wonder if the worker process is unable to save to disk for some
reason... I ran filemon during one test and it did not reveal any problems.
"John Timney (MVP)" <x_****@timney.eclipse.co.ukwrote in message
news:rt******************************@eclipse.net. uk...

您对requestLengthDiskThreshold的理解是正确的,

表示基础流过早关闭。


出于兴趣,请尝试将maxrequestlength设置为大于预期的最大文件大小,并查看问题是否消失。


问候


John Timney(MVP)


" Phil Z." < ph *** @ noemail.noemailwrote in message

新闻:哦************** @ TK2MSFTNGP02.phx.gbl ...
Your understanding of requestLengthDiskThreshold is correct, which
suggests that the underlying stream is being closed prematurely.

Out of interest try setting your maxrequestlength to be significantly
larger than your max file size expected and see if the problem goes away.

Regards

John Timney (MVP)
"Phil Z." <ph***@noemail.noemailwrote in message
news:Oh**************@TK2MSFTNGP02.phx.gbl...

>将ASP.NET 1.1应用程序迁移到2.0后,我们得到无法访问已关闭的文件。上传时出错。我在主题上发现了一些帖子,后来又从使用Html文件输入控件转到使用新的FileUpload控件。

之前,我设置了maxRequestLength
machine.config文件中的属性允许100MB上传成功。在v2.0
应用程序中,我已经在web.config中添加了一个httpRuntime节点,并且像以前一样设置了maxRequestLength = 102400。我还将
requestLengthDiskThreshold值设置为8192.

执行此操作后,可以上载最大为8192KB的文件。我现在已经发现requestLengthDiskThreshold是限制值。通过这个
我的意思是小于requestLengthDiskThreshold
的文件将上传,而大于requestLengthDiskThreshold
设置的文件会抛出无法访问已关闭的文件。例外。对于阈值输入了许多不同的值,这已经证明是正确的。

我的理解是requestLengthDiskThreshold值设置缓存在内存中的请求的数量,超出此值的数据会暂时写入磁盘。它是否正确?为什么我发现
我的文件上传大小受requestLengthDiskThreshold
设置的限制?

非常感谢 - phil
>After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot
access a closed file" errors when uploading. I found a number of post on
the subject and have since moved from using an Html File Input control to
using the new FileUpload control.

Previously, I had set the maxRequestLength attribute in the
machine.config file to allow 100MB uploads with success. In the v2.0
application I have added an httpRuntime node to the web.config and have
set maxRequestLength=102400 as before. I also set the
requestLengthDiskThreshold value to 8192.

After doing this, files up to 8192KB in size were uploadable. I have now
found that the requestLengthDiskThreshold is the limiting value. By this
I mean that files that are smaller than the requestLengthDiskThreshold
will upload, while files larger than the requestLengthDiskThreshold
setting throw the "Cannot access a closed file" exception. This has
proved true with a number of different values entered for the threshold.

My understanding is that the requestLengthDiskThreshold value sets the
amount of the request that is cached in memory, and data beyond this
value is temporarily written to disk. Is this correct? Why am I finding
that my file upload size is limited by the requestLengthDiskThreshold
setting?

Thanks much -- phil




嗨Phil,


我正在使用以下Web表单来测试FileUpload:


---- 8< ----


<%@ Page Language =" C#" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"

" http:/ /www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< script runat =" server">


protected void UploadButton_Click(object sender,EventArgs e)

{

//指定服务器上的路径

//将上传的文件保存到。

字符串savePath = @" c:\ temp \uploads \" ;;


//之前尝试在文件上执行操作

//,验证FileUpload

//控件是否包含文件。

if(FileUpload1.HasFile )

{

//获取要上传的文件的名称。

String fileName = FileUpload1.FileName;


//附加要上传到路径的文件名。

savePath + = fileName;

//调用SaveAs方法保存

//将文件上传到指定的文件路径。

//这个例子没有执行所有

//必要的错误检查。

//如果一个文件同名

//已经存在于指定的路径中,

//上传的文件会覆盖它。

FileUpload1.SaveAs(savePath);


//通知用户文件名

//保存在。

UploadStatusLabel.Text ="你的文件已保存为 + fileName;

}

else

{

//通知用户文件未上传。

UploadStatusLabel.Text ="您没有指定要上传的文件。" ;;

}


}

< / script>

< html xmlns =" http://www.w3.org/1999/xhtml" >

< head id =" Head1" runat =" server">

< title> FileUpload示例< / title>

< / head>

< body> ;

< form id =" form1" runat =" server">

< div>

< h4>选择要上传的文件:< / h4>

< asp:FileUpload id =" FileUpload1"

runat =" server">

< / asp:FileUpload>


< br />< br />


< asp:Button id =" UploadButton"

Text =" Upload file"

OnClick =" UploadButton_Click"

runat =" server">

< / asp:按钮>


< hr />


< asp:Label id =" UploadStatusLabel"

runat =" server">

< / asp:Label>

< / div>

< /表格>

< / body>

< / html>


----> 8 --- -


在web.config中使用以下设置:


< httpRuntime maxRequestLength =" 102400" />


我能够毫无问题地上传高达60MB的文件。


我也在这里阅读了一些类似的问题:
http://channel9.msdn.com/ShowPost.aspx? PostID = 106570


我想你是直接从流中读的?你能在这里发布你的

代码清单吗?谢谢。


MaxRequestLength:限制传入请求的大小,这限制了上传文件的大小




RequestLengthDiskThreshold:控制请求是否在处理时暂时存储在内存中或磁盘上。


如果使用FileMon监视asp.net工作进程,当上传文件的大小超过requestLengthDiskThreshold时,你会注意到

,创建了一个

临时文件,例如:

C:\ WINDOWS \ MicroStoswork.NET \ Framework \v2.0.50727 \Temp orary ASP.NET

Files \fileuploadsizelimit\ccca1291\f22cc828,如果文件小于

RequestLengthDiskThreshold,没有创建临时文件。


所以我猜你的问题是asp.net无法创建临时文件
上传期间
。但既然你提到你已经运行过FileMon和

它没有发现任何问题,那么问题可能存在于某个地方之前

asp.net试图创建临时文件。


我想在做更多研究之前先看看你的代码。


此致,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


=== ===============================================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,也没有授予任何权利。

Hi Phil,

I''m using following web form to test the FileUpload:

----8<----

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void UploadButton_Click(object sender, EventArgs e)
{
// Specify the path on the server to
// save the uploaded file to.
String savePath = @"c:\temp\uploads\";

// Before attempting to perform operations
// on the file, verify that the FileUpload
// control contains a file.
if (FileUpload1.HasFile)
{
// Get the name of the file to upload.
String fileName = FileUpload1.FileName;

// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the
// uploaded file to the specified path.
// This example does not perform all
// the necessary error checking.
// If a file with the same name
// already exists in the specified path,
// the uploaded file overwrites it.
FileUpload1.SaveAs(savePath);

// Notify the user of the name of the file
// was saved under.
UploadStatusLabel.Text = "Your file was saved as " + fileName;
}
else
{
// Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload.";
}

}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>FileUpload Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h4>Select a file to upload:</h4>

<asp:FileUpload id="FileUpload1"
runat="server">
</asp:FileUpload>

<br /><br />

<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>

<hr />

<asp:Label id="UploadStatusLabel"
runat="server">
</asp:Label>
</div>
</form>
</body>
</html>

---->8----

With following settings in web.config:

<httpRuntime maxRequestLength="102400" />

I was able to upload files up to 60MB without problem.

I also have read some similar problems here:
http://channel9.msdn.com/ShowPost.aspx?PostID=106570

I guess you''re reading directly from the stream? Could you please post your
code listing here? Thanks.

MaxRequestLength: limits the size of incoming requests, which limits the
size of the uploaded file.

RequestLengthDiskThreshold: controls whether the request is temporarily
stored in memory or on disk while being processed.

If you use FileMon to monitor the asp.net worker process, you will notice
when the uploaded file''s size exceeds requestLengthDiskThreshold, a
temporary file gets created at such as:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\fileuploadsizelimit\ccca1291\f22cc828, if the file is smaller than
the RequestLengthDiskThreshold, the temporary file is not created.

So I guess your problem is asp.net was unable to create the temporary file
during uploads. But since you mentioned that you''ve already run FileMon and
it did not reveal any problems, the problem may exist somewhere before
asp.net trying to create the temporary file.

I want to take a look at your code before doing more research.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于FileUpload大小受requestLengthDiskThreshold限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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