简体   繁体   中英

Change maximum request length in asp.net mvc without modifying web.config

As the question suggest is it possible to change the maximum request length in an asp.net mvc project without modifying the web.config file?

The project is on several client servers which I don't want to have to manually change for each one so hoping I can put something in global.asax to write it instead or similar?

EDIT: OR is it possible to add another config file with just the settings I want to overwrite?

I don't think that's possible, as the web config stores the configuration values that your application uses to define how it behaves - in this case, the length of the data you require to be passed on.

You would need to modify the web.config as follows:


<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>

And if you are on IIS7 above, the following needs to be configured as well:

<system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>

Additional Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes

Some options you have are:

  1. Powershell script that would read your web.config files on the different servers and update the configuration values accordingly.

  2. Uploading the web config directly via FTP or publish.

  3. Modifying the web config directlyon the server instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM