gpt4 book ai didi

asp.net - 上传时文件大小超过默认大小

转载 作者:行者123 更新时间:2023-12-04 04:58:48 25 4
gpt4 key购买 nike

我在 ASP.NET MVC 中工作。我正在尝试上传一个文件,在小文件的情况下成功,但如果文件很大,我会收到以下错误。

Maximum request length exceeded.

以下是我的表格。
@using (@Html.BeginForm("Method","Controller",FormMethod.Post,new{enctype="multipart/form-data"}))
{
<input type="file" name="file" id="file"/>
<input type="submit" value="Submit"/>
}

以下是 Controller 方法。
[HttpPost]
public ActionResult Method(HttpFileBase file)
{
string path = System.IO.Path.Combine(Server.MapPath("~/Files"), file.FileName);

file.SaveAs(path);
}

当文件很小(即 1-2Mb)时,相同的代码工作正常,但我正在尝试上传未上传的 19Mb 文件。我不知道如何指定文件长度以及如何删除上述错误。请帮帮我。

最佳答案

在 System.Web 节点下的 web.config 中指定

<httpRuntime maxRequestLength="NNN" />

其中 NNN 是以千字节为单位的文件大小

关于asp.net - 上传时文件大小超过默认大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16402825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com