上传附件 - 限制文件大小 - IE无法显示网页

时间:2010-09-21 19:11:37

标签: asp.net file-upload

我正在尝试测试,如果我上传超过3mb的文件大小我是否会收到错误,但我得到IE错误(见下文)

这是我的代码。 - 我想要的是如果用户尝试上传超过3mb的文件大小显示错误。

 if (fUpload.HasFile)
 {
   // Get the size in bytes of the file to upload.            
   int fileSize = fUpload.PostedFile.ContentLength;
  // Allow only files less than 3145728 bytes (approximately 3 MB) to be uploaded.
  if (fileSize > 3145728) //if (fUpload.PostedFile.ContentLength <= 3072) 
  {
     ..............
     .............
  }
  else
  {
    // Notify the user why their file was not uploaded.                
    this.lblStatus.Text = "Your file was not uploaded because it exceeds the 3 MB size limit.";
  }
}

<system.web>
    <httpRuntime maxRequestLength="3145728" />


Internet Explorer cannot display the webpage
This problem can be caused by a variety of issues, including: 

•Internet connectivity has been lost.
•The website is temporarily unavailable.
•The Domain Name Server (DNS) is not reachable.
•The Domain Name Server (DNS) does not have a listing for the website's domain.
•There might be a typing error in the address.
•If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.

2 个答案:

答案 0 :(得分:0)

你在服务器端这样做。这意味着该文件已经开始上传到服务器。我也找不到解决办法,我不知道是否有这个问题。

答案 1 :(得分:0)

这是我如何解决它:

默认情况下,您应该能够上传最大4MB的文件,MaxRequestLength则以Kilo字节为单位。所以,默认值是4096KB。如果您尝试上传大小超过4MB的文件,则会出现错误。所以,将其增加到大约25Mb或大量。然后,您应该能够在代码中跟踪文件大小。

<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>