file size upload limitation in ASP.NET MVC: more than 1 maxRequestLength setting in web.config(s)

喜你入骨 提交于 2019-11-29 07:21:47

问题


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.


回答1:


See my answer here: ASP.NET MVC and httpRuntime executionTimeout




回答2:


I believe the Path attribute shouldn't start or end with a "/" - so you should have:

<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>

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:

The following code example demonstrates how to set the uploaded file size limit to 128 KB for only the page specified.

<configuration>
  <location path="UploadPage.aspx">
    <system.web>
      <httpRuntime maxRequestLength="128"/>
    </system.web>
  </location>
</configuration>



回答3:


This solution is incomplete, because IIS 7 has "Request Filtering" settings limited to 30Mb by default. You should increase this parameter, see details in my blogpost



来源:https://stackoverflow.com/questions/1038742/file-size-upload-limitation-in-asp-net-mvc-more-than-1-maxrequestlength-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!