ASP 文件上传静默失败

2024-01-30

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

Page:

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

EDIT :我已经尝试过下面接受的答案,或者我是这么想的。再看了一下才发现有two <system.webServer>我的 web.config 中的部分都需要更改。


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

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

<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="524288000"/>
  </requestFiltering>
</security>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP 文件上传静默失败 的相关文章

随机推荐