我在使用 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;
}
}
编辑:我已经尝试过下面接受的答案,或者我是这么认为的。再次查看,我发现有两个 <system.webServer>
我的 web.config 中的部分都需要更改。
最佳答案
如果您使用的是 iis7,这将解决您的问题。我测试上传文件大小超过400MB,
在 web.config 文件中的 element 下添加以下配置。
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
关于asp.net - ASP 文件上传静默失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9705474/