面临的错误:HTTP 错误 404.13 - 未找到/请求过滤模块配置为拒绝超过请求内容长度的请求
编辑:决定改写和整理我的问题。
每当我通过 FileUpload Control 提交文件时,我都会遇到此错误。我想将文件大小设置为 5MB,如果选择的文件超过 5MB,它会显示错误消息(例如文件超出文件限制,请重试)。以下是我的代码。
**
网页1.aspx.cs
**
protected void Button1_Click(object sender, EventArgs e)
{
string gen = "Pending";
//This portion is for storing files in database
FileInfo fi = new FileInfo(FileUpload1.FileName);
byte[] documentContent = FileUpload1.FileBytes;
string name = fi.Name;
//string extn = fi.Extension;
string filextn = Path.GetExtension(FileUpload1.FileName);
//This portion is for storing files in folder
string filepath = Path.GetExtension(FileUpload1.FileName);
if (filepath.ToLower() != ".pdf" && filepath.ToLower() != ".png" && filepath.ToLower() != ".gif" && filepath.ToLower() != ".zip")
{
lblmessage.Text = "Only pdf, png and gif file are accepted";
}
else
{
//int filesize = FileUpload1.PostedFile.ContentLength;
if (FileUpload1.PostedFile.ContentLength > 5242880)
{
//lblmessage.Text = "Maximum size (5MB) exceeded";
Response.Redirect("Error.aspx");
}
}
网络配置
据我了解 maxRequestLength 以千字节(KB)为单位
<httpRuntime targetFramework="4.7.2" maxRequestLength="5000" />
并且,maxAllowedContentLength 以 BYTES 为单位测量
<requestFiltering> <requestLimits maxAllowedContentLength="5242880" /> </requestFiltering>
我尝试过的其他事情
- 我在配置编辑器中配置了 maxRequestLength;仍然失败。
信用:https ://weblog.west-wind.com/posts/2016/apr/06/configuring-aspnet-and-iis-request-length-for-post-data https://hoststud.com/resources/how -to-increas-the-maximum-upload-file-size-in-iis.422/