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

Ale*_*x42 17 asp.net-mvc file-upload web-config maxrequestlength

我想为maxRequestLength设置多个设置 - 文件大小上传限制(例如,一个用于文件/新建,另一个用于图片/新建).我的所有操作都采用其他参数(例如/ File/New?folderId = 234).

单个设置按预期工作:

<httpRuntime executionTimeout="60" maxRequestLength="1024" />
Run Code Online (Sandbox Code Playgroud)

我尝试在根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>
Run Code Online (Sandbox Code Playgroud)

我试图将另一个web.config放在一个特定的视图文件夹中(例如/ Views/Picture/...),就像它在经典的Webform ASP.NET中一样,但是这似乎没有做到这一点......

<location path="">
    <system.web>
        <httpRuntime executionTimeout="60" maxRequestLength="1024" />
    </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

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

Zha*_*uid 11

我相信Path属性不应该以"/"开头或结尾 - 所以你应该:

<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>
Run Code Online (Sandbox Code Playgroud)

您的虚拟或物理目录级Web.config不应具有<location>元素.

那应该是你排除.

Location元素的文档甚至有这样一个例子:

以下代码示例演示如何仅将指定页面的上载文件大小限制设置为128 KB.

<configuration>
  <location path="UploadPage.aspx">
    <system.web>
      <httpRuntime maxRequestLength="128"/>
    </system.web>
  </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)