ASP.NET MVC 中的文件大小上传限制:web.config 中的 maxRequestLength 设置超过 1
我希望对 maxRequestLength - 文件大小上传限制有超过 1 个设置(例如,一个用于文件/新建,另一个用于图片/新建)。 我的所有操作都采用附加参数(例如/File/New?folderId=234)。
单个设置按预期工作:
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
我尝试在根 web.config 中使用 2 个位置部分进行 2 个设置,但没有成功。 我不知道在“路径”中写什么 - 视图的物理 aspx 页面,或控制器+操作...但是,似乎没有任何效果。
<location path="/File/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="4096" />
</system.web>
</location>
<location path="/Picture/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
我尝试将另一个 web.config 放在特定的视图文件夹中(例如 /Views/Picture/...),就像它在经典 Webform ASP.NET 中工作一样,但这似乎也不起作用...
<location path="">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
否无论我做什么,都只会应用 httpRuntime.maxRequestLength 的一个值 - 在(根)web.config...system.web 中。
I'd like to have more than 1 setting for maxRequestLength - file size upload limitation (e.g. one for File/New, other for Picture/New). All of my Actions take additional parameters (e.g. /File/New?folderId=234).
Single setting works as expected:
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
I tried to have 2 settings with 2 location sections in the root web.config, but without any success. I'm not sure what to write in "path" - physical aspx page of a view, or controller+action... however, nothing seems to work.
<location path="/File/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="4096" />
</system.web>
</location>
<location path="/Picture/">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
I tried to put another web.config in a specific view folder (e.g. /Views/Picture/...), like it works in classic Webform ASP.NET, but this doesn't seem to do the trick either...
<location path="">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
No matter what I do, only one value for httpRuntime.maxRequestLength is applied - that in (root) web.config...system.web.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 Path 属性不应该以“/”开头或结尾 - 所以你应该:
你的虚拟或物理目录级 Web.config 不应该有。 元素。
那应该可以解决你的问题。
Location 元素 的文档甚至有这个例子:
I believe the Path attribute shouldn't start or end with a "/" - so you should have:
Your virtual or physical directory–level Web.config's shouldn't have the <location> elements.
That should sort you out.
The docs for the Location element even have this very example: