做了一个上传文件的程序,如果上传只有几M的文件就会执行成功.如果上传比较大的文件,就会转到'该页无法显示'的错误页面,在程序里设置断点,发现上传大文件的时候根本连那个事件都没有进去,整个程序代码都没有被执行,调试不了,各位高手有没有遇到过类似的问题,帮忙给解决一下了.!

解决方案 »

  1.   

    对于asp.net,默认只允许上传2M文件,增加如下配置,一般可以自定义最大文件大小.<httpRuntimeexecutionTimeout="300"maxRequestLength="40960"useFullyQualifiedRedirectUrl="false"/>如果还不行,可以使用思归提供的方案:我们在上传大文件时都遇到过这样或那样的问题。设置很大的maxRequestLength值并不能完全解决问题,因为ASP.NET会block直到把整个文件载入内存后,再加以处理。实际上,如果文件很大的话,我们经常会见到InternetExplorer显示"Thepagecannotbedisplayed-CannotfindserverorDNSError",好像是怎么也catch不了这个错误。为什么?因为这是个clientside错误,serverside端的Application_Error是处理不到的,可以参考这个帖子研究一下产生这个错误的机理。handlingservererrorwhenuploadfiletoolarge解决的方法是利用隐含的HttpWorkerRequest,用它的GetPreloadedEntityBody和ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据IServiceProviderprovider=(IServiceProvider)HttpContext.Current;
    HttpWorkerRequestwr=(HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
    byte[]bs=wr.GetPreloadedEntityBody();
    ....
    if(!wr.IsEntireEntityBodyIsPreloaded())
    {
    intn=1024;
    byte[]bs2=newbyte[n];
    while(wr.ReadEntityBody(bs2,n)>0)
    {
    .....
    }
    }
      

  2.   

    有问题先baidu一下,不要浪费可用分咯
      

  3.   

    我也遇到同样的问题,请问楼上的这段代码IServiceProviderprovider=(IServiceProvider)HttpContext.Current;
    HttpWorkerRequestwr=(HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
    byte[]bs=wr.GetPreloadedEntityBody();
    ....
    if(!wr.IsEntireEntityBodyIsPreloaded())
    {
    intn=1024;
    byte[]bs2=newbyte[n];
    while(wr.ReadEntityBody(bs2,n)>0)
    {
    .....
    }
    }
    写在什么地方??