ASP.NET MVC中的文件大小上传限制:web.config(s)中的maxRequestLength设置超过1个。

问题描述 投票:17回答:2

我想为maxRequestLength--文件大小上传限制设置多于1个(例如FileNew有一个,PictureNew有另一个),我的所有Action都需要额外的参数(例如FileNew?文件夹Id=234)。我所有的Action都需要额外的参数(例如FileNew?文件夹Id=234)。

单一的设置可以正常工作。

<httpRuntime executionTimeout="60" maxRequestLength="1024" />

我试着在web.config根目录下有两个设置和两个位置部分,但没有成功。我不知道在 "路径 "中应该写什么--是视图的物理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放在一个特定的视图文件夹里(例如ViewsPicture...),就像在经典的Webform ASP.NET中一样,但这似乎也没有用......。

<location path="">
    <system.web>
        <httpRuntime executionTimeout="60" maxRequestLength="1024" />
    </system.web>
</location>

无论我怎么做,httpRuntime.maxRequestLength只有一个值被应用--在(root)web.config...system.web中。

asp.net-mvc file-upload web-config maxrequestlength
2个回答
11
投票

我相信路径属性不应该以""开头或结尾,所以你应该有。

<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不应该有<location>元素。

这样你就可以解决了。

文档中的 位置要素 甚至有这样的例子。

下面的代码演示了如何将上传的文件大小限制设置为128KB,只用于指定的页面。

<configuration>
  <location path="UploadPage.aspx">
    <system.web>
      <httpRuntime maxRequestLength="128"/>
    </system.web>
  </location>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.