【问题标题】:getting connection was interrupted for uploading files bigger than 4 MB上传大于 4 MB 的文件导致连接中断
【发布时间】:2011-10-08 10:13:16
【问题描述】:

我正在使用 ASP.Net 开发一些网站,用于上传和处理一些 MS Word 文档。我得到连接在 Chrome 中被中断或连接在 Firefox 中被重置以上传大于 4 MB 的文档。我一按下按钮就收到此错误,它几乎没有上传任何内容。

这是我认为导致错误的代码部分(我使用通用输入类型=文件作为上传槽)

 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);

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

【问题讨论】:

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

标签: c# asp.net file-upload ms-word


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-13
    • 2011-11-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 2014-03-04
    相关资源
    最近更新 更多