ASP FileUpload无声失败

时间:2012-03-14 15:59:38

标签: asp.net file-upload

我在使用FileUpload进行大文件时遇到问题。如果我上传一个小文件(~10kB),它可以正常工作。上传一个大文件(~60MB)不会引发异常,它只是重新加载页面。在有人要求之前:<httpRuntime maxRequestLength="2097151" executionTimeout="3600" waitChangeNotification="1" maxWaitChangeNotification="3600" requestValidationMode="2.0" />

页:

<%@ 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;
}
}

编辑:我已经尝试过以下接受的答案,或者我认为。再看一遍,我发现我的web.config中有两个 <system.webServer>部分,都需要进行更改。

4 个答案:

答案 0 :(得分:2)

如果您使用的是iis7,这将解决您的问题。我测试的上传文件大小超过400MB,

在元素下的web.config文件中添加以下配置。

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

答案 1 :(得分:0)

如果这是在IIS7上,您还需要重新配置它以接受文件&gt; ~30MB:http://www.iislogs.com/steveschofield/iis7-post-40-adjusting-file-upload-size-in-iis7

答案 2 :(得分:0)

在您的代码中生成executionTimeout =“9000”...

答案 3 :(得分:0)

查看SlickUpload:http://slickupload.com/

即使您不打算使用免费版本,他们也可以在他们的文档中讨论缓解IIS 6和IIS 7中的请求限制:

http://slickupload.com/documentation/installation

特别是浏览器到该页面并为“requestFiltering”执行Control-F,并查看他们提到的添加到web.config的部分。