我爱Aspx >> Asp.Net >> 解决ASP.NET上传文件大小限制对于asp.net,默认只允许上传2M文件,增加如下配置,一般可以自定义最大文件大小.
<httpRuntime
executionTimeout="300"
maxRequestLength="40960"
useFullyQualifiedRedirectUrl="false"/>
如果还不行,可以使用思归提供的方案:
我们在上传大文件时都遇到过这样或那样的问题。设置很大的maxRequestLength值并不能完全解决问题,因为ASP.NET会block直到把整个文件载入内存后,再加以处理。实际上,如果文件很大的话,我们经常会见到Internet Explorer显示 "The page cannot be displayed - Cannot find server or DNS Error",好像是怎么也catch不了这个错误。为什么?因为这是个client side错误,server side端的Application_Error是处理不到的,可以参考这个帖子研究一下产生这个错误的机理。
handling server error when upload file too large
解决的方法是利用隐含的HttpWorkerRequest,用它的GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据
IServiceProvider provider = (IServiceProvider) HttpContext.Current;
HttpWorkerRequest wr = (HttpWorkerRequest) provider.GetService(typeof(HttpWorkerRequest));
byte[] bs = wr.GetPreloadedEntityBody();
....
if (!wr.IsEntireEntityBodyIsPreloaded())
{
int n = 1024;
byte[] bs2 = new byte[n];
while (wr.ReadEntityBody(bs2,n) >0)
{
.....
}
}
Chris Hynes为我们提供了这样的一个方案(用HttpModule),该方案除了允许你上传大文件外,还能实时显示上传进度:
ASP.NET Upload Magic Part 2
这里有他讲座的PPT文件:
Uploading with ASP.NET (part 1)
Uploading with ASP.NET (part 2)
asp.net下的日历控件源代码[04-29]
关于Asp.Net中的编程实现下载[04-29]
.Net里的哈希表和串行化[04-29]
建立ASP.NET开发平台[04-29]
.NET Framework-Microsoft Visua..[04-29]
.NET Framework[04-29]
.NET Framework 概要[04-29]
.NET 共享对象类别库[04-29]
ASP.NET[04-29]
Visual Basic.NET语言-基础观念[04-29]
asp.net下的日历控件源代码[04-29]
关于Asp.Net中的编程实现下载[04-29]
UrlReWriter 使用经验小结[04-29]
RadioButton Web 控件[04-29]
RadioButtonList Web 控件[04-29]
ListItem Web 控件[04-29]
CheckBox Web 控件[04-29]
CheckBoxList 控件[04-29]
DropDownList Web 控件[04-29]
DropDownList Web 控件[04-29]