2017-09-17 41 views
0

我已經將所有設置不是配置爲所有文件超過100kb,但仍然嘗試上傳文件並給出404.13錯誤。Asp .Net中的文件上傳錯誤

這是我的web.config配置:

<security> 
    <requestFiltering> 
    <requestLimits> 
     <headerLimits> 
     <add header="Content-type" sizeLimit="100000" /> 
     </headerLimits> 
    </requestLimits> 
    </requestFiltering> 
</security> 

<httpRuntime maxRequestLength="100000"></httpRuntime> 

,我已經寫在C#代碼如下:

 if (fuUpload.HasFile) 
    { 
     int fileSize = fuUpload.PostedFile.ContentLength; 
     if (fileSize > 100000) 
     { 
      //ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + sizeError + "');", true); 
      lblSizeError.Text = "File size should be less then 100Kb"; 
     } 
     else 
     { 
      fuUpload.SaveAs(Server.MapPath("~/RegistrationUploads/" + fuUpload.FileName)); 

      ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + success + "');", true); 
     } 
    } 
    else 
    { 
     ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('" + uploadFile + "');", true); 
    } 

它的文件少做工精細,然後100KB和投擲的錯誤如果沒有選擇文件。

如果大小超過100kb,我希望它拋出錯誤。

回答

0

設置最大文件大小(102400Bytes -> 100KB)和執行時間1200默認爲360(6分鐘):

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
     <httpRuntime maxRequestLength="102400" executionTimeout="1200" /> 
    </system.web> 
</configuration> 

而且你可以處理請求的最大的例外超過。