【发布时间】: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