The default upload file for the ASP. NET program is limited by the size of 4M. The default is 30M under IIS7. Therefore, several projects need to be configured to support uploads of large files (2G max).
1. Configuration Error
Description: An error occurred while processing the configuration file required to service the request. Please check the specific error details below and modify the configuration file as appropriate.
Parser Error Message: The value of the property "maxRequestLength" is invalid. Error: The value must be within the range of 0-2097151.
If the following error occurs:
Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code. Exception Details: System.Web.HttpException: The maximum request length was exceeded. |
That's because the configured maxRequestLength exceeds 2097151.
Workaround 1:
Web. config configuration:
<configuration><system.web>
Note the modification time-out: executiontimeout. Units are: seconds.
Workaround 2: Modify the Application_BeginRequest method of the Global.asax.cs:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
Using System.Web.Configuration;
void
Application_BeginRequest(
object
sender, EventArgs e)
{
//本代码的功能是检查页面请求的大小,如果超过了配置文件maxRequestLength的设定值,就提示用户超过了所允许的文件大小。
//从配置文件里得到配置的允许上传的文件大小
HttpRuntimeSection runTime = (HttpRuntimeSection)WebConfigurationManager.GetSection(
"system.web/httpRuntime"
);
//maxRequestLength 为整个页面的大小,不仅仅是上传文件的大小,所以扣除 100KB 的大小,
//maxRequestLength单位为KB
int
maxRequestLength = (runTime.MaxRequestLength) * 1024;
//当前请求上下文的HttpApplication实例
//HttpContext context = ((HttpApplication)sender).Context;
//判断请求的内容长度是否超过了设置的字节数
if
(Request.ContentLength > maxRequestLength)
{
#region 不理解这些代码存在的意义
/*
//得到服务对象
IServiceProvider provider = (IServiceProvider)context;
HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
//检查请求是否包含正文数据
if (workerRequest.HasEntityBody())
{
//请求正文数据的长度
int requestLength = workerRequest.GetTotalEntityBodyLength();
//得到加载的初始字节数
int initialBytes = 0;
if (workerRequest.GetPreloadedEntityBody() != null)
initialBytes = workerRequest.GetPreloadedEntityBody().Length;
//检查是否所有请求数据可用
if (!workerRequest.IsEntireEntityBodyIsPreloaded())
{
byte[] buffer = new byte[512000];
//设置要接收的字节数为初始字节数
int receivedBytes = initialBytes;
//读取数据,并把所有读取的字节数加起来,判断总的大小
while (requestLength - receivedBytes >= initialBytes)
{
//读取下一块字节
initialBytes = workerRequest.ReadEntityBody(buffer, buffer.Length);
//更新接收到的字节数
receivedBytes += initialBytes;
}
initialBytes = workerRequest.ReadEntityBody(buffer, requestLength - receivedBytes);
}
}
*/
#endregion
//注意这里可以跳转,可以直接终止;在VS里调试时候得不到想要的结果,通过IIS才能得到想要的结果;FW4.0经典或集成都没问题
htm = htm&(
"请求大小"
+ Request.ContentLength);
Response.End();
}
}
|
2. Problem: HTTP error 404.13-not Found
HTTP Error 404.13-not Found The request filtering module is configured to reject requests that exceed the requested content length. The most probable cause: The request filtering on the • Web server is configured to reject the request because the content length exceeds the configured value. Actions you can try: • Confirm the Configuration/system.webserver/security/requestfiltering/[email in the ApplicationHost.config or Web. config file Protected] settings. Detailed error message: Module Requestfilteringmodule Notice BeginRequest Processing program pagehandlerfactory-integrated Error code 0x00000000 |
Cause: The request filtering on the WEB server is configured to reject the request because the content length exceeds the configured value (IIS 7 default file upload is 30M Large).
FIX: change the ASP. net file Upload size limit
Modifying the applicationhost.config of IIS
File Location:%windir%/system32/inetsrv/config/applicationhost.config
Locate the <requestFiltering> node, which defaults to the <requestlimits maxallowedcontentlength= "Upload size value (in bytes)"/> element under the node. Add the following elements for this node:<requestlimits maxallowedcontentlength= "2147483647"/> (upload size will be changed to 2G)
Web. config, add the following
<configuration>
<system.web>
</system.web>
</configuration>
Description
HttpRuntime configures the ASP. NET HTTP runtime settings to determine how to handle requests to an ASP.
maxRequestLength (indicates the maximum file upload size supported by ASP.)
Specifies the input stream buffering threshold limit, in kilobytes. This restriction can be used to prevent denial of service attacks, such as denial of service attacks that result from users sending large files to the server.
The default value is 4096 (4 MB), and the maximum value is only 2097151K.
Executiontimeout
Specifies the maximum number of seconds that a request is allowed to execute before it is automatically closed by ASP. The default is 90 seconds.
This time-out property is only applicable if the Debug property in the compilation element is False. To help avoid shutting down your application during debugging, do not set this timeout property to a large value.
Web. config, add the following to the <system.webServer> node
<security>
<requestfiltering >
<requestlimits maxallowedcontentlength= "2147483647" ></requestLimits>
</requestFiltering>
</security>
The above-mentioned Maxallowedcontentlengt are in BK units.
ASP. NET files/large file uploads need to be configured for project grooming