尽管在 Web.Config 中设置了配置,但仍被定向到 HTTP 错误 404.13 页面
Kept being directed to HTTP Error 404.13 page despite configuration set in Web.Config
面临错误:HTTP 错误 404.13 - 未找到/请求过滤模块配置为拒绝超过请求内容长度的请求
编辑:决定重新措辞并整理我的问题。
每当我通过 FileUpload 控件提交文件时,我总是遇到这个错误。我想将文件大小设置为 5MB,如果选择的文件超过 5MB,它会显示一条错误消息(例如文件超出文件限制,请重试)。以下是我的代码。
**
WebPage1.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");
}
}
Web.Config
根据我的理解,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-increase-the-maximum-upload-file-size-in-iis.422/
尝试以下配置
Web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2" maxRequestLength="1048576" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample_File_Upload.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<p>
</p>
<p>
<asp:Button ID="UploadFile" runat="server" OnClick="UploadFile_Click" Text="Upload File" />
</p>
<asp:Label ID="message" runat="server"></asp:Label>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
namespace Sample_File_Upload
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadFile_Click(object sender, EventArgs e)
{
if(FileUpload1.PostedFile.ContentLength > 5242880)
{
message.Text = "Maximum size allowed is 5MB.";
}
else
{
message.Text = "File uploaded successfully";
}
}
}
}
面临错误:HTTP 错误 404.13 - 未找到/请求过滤模块配置为拒绝超过请求内容长度的请求
编辑:决定重新措辞并整理我的问题。
每当我通过 FileUpload 控件提交文件时,我总是遇到这个错误。我想将文件大小设置为 5MB,如果选择的文件超过 5MB,它会显示一条错误消息(例如文件超出文件限制,请重试)。以下是我的代码。
**
WebPage1.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");
}
}
Web.Config
根据我的理解,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-increase-the-maximum-upload-file-size-in-iis.422/
尝试以下配置
Web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2" maxRequestLength="1048576" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample_File_Upload.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<p>
</p>
<p>
<asp:Button ID="UploadFile" runat="server" OnClick="UploadFile_Click" Text="Upload File" />
</p>
<asp:Label ID="message" runat="server"></asp:Label>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
namespace Sample_File_Upload
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadFile_Click(object sender, EventArgs e)
{
if(FileUpload1.PostedFile.ContentLength > 5242880)
{
message.Text = "Maximum size allowed is 5MB.";
}
else
{
message.Text = "File uploaded successfully";
}
}
}
}