maxRequestLength 和 maxAllowedContentLength 哪个优先?
在更改允许上传的最大文件大小时,我偶然发现了这两个设置。
在sytem.web中,您有带有maxRequestLength的http运行时节点。 在system.webServer中,您有requestLimits和maxAllowedContentLength。
现在哪个优先于另一个?我们是否需要同时设置两者,还是最后一项(IIS7 的那个)就足够了?
While changing the maximum allowed file size for upload I stumbled on those two settings.
In the sytem.web you have the http runtime node with maxRequestLength.
In the system.webServer you have the requestLimits with maxAllowedContentLength.
Now which gets the priority over the other? And do we need to set both or is the last one (the one for IIS7) enough?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
maxRequestLength 指示 ASP.NET 支持的最大请求大小,而 maxAllowedContentLength 指定 IIS 支持的请求中的最大内容长度。因此,您需要同时设置两者才能上传大文件:较小的文件“优先”。
(我从 http://forums.iis.net/t/1169846.aspx 获取此内容 - 信用)
您可以通过编辑相应的 web.config 文件将两者设置为特定站点的本地甚至站点内的文件夹。如果文件(好吧,请求)长度小于 maxAllowedContentLength 但大于 maxRequestLength,用户将获得标准 (ASPX) 错误页面(如果有)。如果相反,他将收到 IIS 错误页面。因此,您可能希望将 maxAllowedContentLength 设置为非常大的值(仅适用于该网站/文件夹),然后将限制值设置为 maxRequestLength。
最后,请记住 maxRequestLength 的单位是 KB,而 maxAllowedContentLength 的单位是 BYTES!
maxRequestLength indicates the maximum request size supported by ASP.NET, whereas maxAllowedContentLength specifies the maximum length of content in a request supported by IIS. So you need to set both in order to upload large files: the smaller one "takes priority".
(I picked this up from http://forums.iis.net/t/1169846.aspx -- credit where it's due.)
You can set both to be local to a specific site or even a folder within a site by editing the appropriate web.config file. If the file (well, request) length is less than maxAllowedContentLength but more than maxRequestLength, the user will get your standard (ASPX) error page, if you have one. If it's the other way around, he'll get an IIS error page instead. For that reason, you might want to have maxAllowedContentLength to a very large value (just for this website/folder) and then have the limiting value be maxRequestLength.
Finally, remember that maxRequestLength is in KB whereas maxAllowedContentLength is in BYTES!
简短而甜蜜的答案是,两者中较小的一个将优先。不过,我的建议是,建议将 maxRequestLength 设置为两者中较小的一个,因为如果超过该值,您可以在 Global.asax 的 Application_Error 事件中捕获异常。如果超过 maxAllowedContentLength,IIS 将首先处理它,而不是 ASP.NET,这使得代码中的处理变得更加棘手。
The short and sweet answer is that the smaller of the two will take precedence. A word of advice though- in my opinion it is advisable to set maxRequestLength to be the smaller of the two as you can catch an exception in the Application_Error event of your Global.asax should it be exceeded. If you exceed maxAllowedContentLength first IIS will deal with it instead of ASP.NET, making it trickier to deal with in code.