C# 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13129746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to ignore the maxRequestLength limit of 2GB file uploads?
提问by Steven
Here's where I'm setting maxRequestLengthto 2GB (the max value), which indicates the maximum request size supported by ASP.NET:
这是我设置maxRequestLength为 2GB(最大值)的地方,它表示 ASP.NET 支持的最大请求大小:
<system.web>
<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
...
and here I'm setting the maxAllowedContentLengthto 4GB (the max value), which specifies the maximum length of content in a request supported by IIS
在这里我将 设置maxAllowedContentLength为 4GB(最大值),它指定了 IIS 支持的请求中内容的最大长度
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295"/>
</requestFiltering>
</security>
...
I'd like to be able to upload files up to 4GB, but I'm limited by the maxRequestLengthfield.
我希望能够上传最大 4GB 的文件,但我受到该maxRequestLength领域的限制。
I noticed that this third party upload tool (http://www.element-it.com/onlinehelp/webconfig.html) has a ignoreHttpRuntimeMaxRequestLengthproperty, which allows it to upload files up to 4GB.
我注意到这个第三方上传工具 (http://www.element-it.com/onlinehelp/webconfig.html) 有一个ignoreHttpRuntimeMaxRequestLength属性,允许它上传最大 4GB 的文件。
Does anyone know if I can ignore the maxRequestLengthvalue like this other upload tool does?
有谁知道我是否可以maxRequestLength像其他上传工具那样忽略该值?
采纳答案by Erik Philips
Considering the Type of MaxRequestLengthis a Int, at the moment there is no way to parse a value higher than Int.Maxcorrectly.
考虑到MaxRequestLength的 Type是Int,目前无法正确解析高于Int.Max的值。
I heard they might be increasing IIS8 but nothing concrete from Microsoft as of yet. The only way I've seen in .Net 4.5 is to use HttpRequest.GetBufferlessInputStreamwhich
我听说他们可能会增加 IIS8,但微软目前还没有具体的内容。我在.NET 4.5中看到的唯一方法是使用HttpRequest.GetBufferlessInputStream哪些
Gets a Stream object that can be used to read the incoming HTTP entity body, optionally disabling the request-length limit that is set in the MaxRequestLength property.
获取可用于读取传入 HTTP 实体正文的 Stream 对象,可选择禁用在 MaxRequestLength 属性中设置的请求长度限制。
回答by vane
You should be able to override the settings inside machine.config by adding the same node into your application's web.config like so. Microsoft has some information about ASP.NET Configuration File Hierarchy and Inheritance.
您应该能够通过像这样将相同的节点添加到应用程序的 web.config 中来覆盖 machine.config 中的设置。Microsoft 有一些关于ASP.NET 配置文件层次结构和继承的信息。
NOTE:Erik Philips is right and the max size of maxRequestLengthis 2,147,483,647 (Int32.MaxValue). This answer is to illustrate how to override a setting defined in machine.config (or any .config) from within your application's web.config/
注意:Erik Philips 是对的,最大大小maxRequestLength为 2,147,483,647 ( Int32.MaxValue)。这个答案是为了说明如何从应用程序的 web.config/ 中覆盖 machine.config(或任何 .config)中定义的设置
<configuration>
...
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
...
...
</system.web>
...
</configuration>
In doing this though, you might also want to increase your timeout or it might, well, time out.
但是,在执行此操作时,您可能还想增加超时时间,或者它可能会超时。
回答by Sanchitos
In my case these were the changes I needed to apply:
就我而言,这些是我需要应用的更改:
<system.web>
<httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" />
</system.web>
<system.webServer>
<serverRuntime uploadReadAheadSize="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
In order to add the serverRuntime follow the intructions in the first answer of this question

