2011-10-08 75 views
1

我正在开发一些带有ASP.Net的网站,用于上传和处理一些MS Word文档。并且我的连接在Chrome中被中断,或者连接在Firefox中重置,以便上传大于4 MB的文档。我一按按钮就会出现此错误,并且几乎没有上传任何内容。因为上传超过4 MB的文件而导致连接中断

这是我认为的部分代码导致错误(我用上传槽共同INPUT TYPE =文件)

if (filMyFile.PostedFile != null) 
    { 
     // Get a reference to PostedFile object 
     HttpPostedFile myFile = filMyFile.PostedFile; 

     // Get size of uploaded file 
     int nFileLen = myFile.ContentLength; 

     // make sure the size of the file is > 0 
     if (nFileLen > 0) 
     { 
      // Allocate a buffer for reading of the file 
      byte[] myData = new byte[nFileLen]; 

      // Read uploaded file from the Stream 
      myFile.InputStream.Read(myData, 0, nFileLen); 

      // Create a name for the file to store 
      string strFilename = Path.GetFileName(myFile.FileName); 



      // Write data into a file 
      WriteToFile(Server.MapPath(strFilename), ref myData); 

你认为问题出在哪里?谢谢

+4

它很可能是IIS设置(或者在IIS之前的防火墙/负载平衡器) - 因为你得到的错误很快。它也可以是ASP .NET MaxRequestLength设置,但是您应该会在应用程序中看到异常。 – driis

回答

3

4MB是在machine.config中设置的默认限制。您可以通过在web.config文件中添加<httpRuntime/>元素来扩展上传文件限制。欲了解更多详情,请阅读this

+0

谢谢,它的工作:) – ePezhman

相关问题