2012-03-14 82 views
2

我在使用FileUpload處理大文件時遇到問題。如果我上傳一個小文件(〜10kB),它可以正常工作。上傳一個大文件(〜60MB)不會引發異常,它只是重新加載頁面。之前有人問:<httpRuntime maxRequestLength="2097151" executionTimeout="3600" waitChangeNotification="1" maxWaitChangeNotification="3600" requestValidationMode="2.0" />ASP FileUpload安靜失敗

頁:

<%@ AutoEventWireup="true" CodeFile="~/LargeFileUploadControl.aspx.cs" Inherits="LargeFileUploadControl" %> 
<html> 
<body> 

<form runat="server"> 
<asp:Label ID="theOnlyLabel" runat="server" Text="Uploaded files will go to a place"/><br /> 
<asp:FileUpload ID="theOnlyUpload" runat="server" /><br /> 
<asp:Button ID="theOnlyButton" onClick="StartUpload" Text="Upload" runat="server" /> 
</form> 
</body> 
</html> 

後面的代碼:

public partial class LargeFileUploadControl:Page 
{ 
public string _uploadDir; 

/// <summary> 
/// Content loaded event handler 
/// </summary> 
protected override void OnLoad(EventArgs e) 
{ 
    base.OnLoad(e); 
    _uploadDir = "D:\\web\\tikt.imaginuity.com\\TIKT\\media\\TIKT\\Global Large Uploads\\"; 
    theOnlyLabel.Text = "Uploaded files will go to " + _uploadDir; 
} 


protected void StartUpload(object sender, EventArgs e) 
{ 
    if (theOnlyUpload.HasFile) 
    { 
     theOnlyLabel.Text = "Uploading..."; 
     theOnlyUpload.SaveAs(_uploadDir + theOnlyUpload.FileName); 
     theOnlyLabel.Text = "File saved to " + _uploadDir + theOnlyUpload.FileName; 
    } 
    else 
    { 
     theOnlyLabel.Text = "No file to upload"; 
    } 

    return; 
} 
} 

編輯:我已經嘗試接受的答案下面,我這樣想着。再次看我發現有兩個<system.webServer>部分在我的web.config中都需要更改。

回答

2

這將解決您的問題,如果您使用的是iis7。我測試了上傳文件大小超過400MB,

在你的web.config文件元素下面添加下面的配置。

<security> 
    <requestFiltering> 
    <requestLimits maxAllowedContentLength="524288000"/> 
    </requestFiltering> 
</security> 
0

使executionTimeout = 「9000」 在您的標記......

0

退房SlickUpload:http://slickupload.com/

即使你不打算使用的免費版本,他們談論減輕在IIS 6和IIS 7的請求限制,在他們的文檔的一個很不錯的工作:

http://slickupload.com/documentation/installation

特別是,瀏覽器到該頁面併爲「requestFiltering」做一個Control-F,並查看他們提到的添加到web.config的部分。