0

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?

7
  • Try to use this property: msdn.microsoft.com/en-us/library/… Commented Jan 27, 2016 at 13:44
  • Any idea what the configSection object relates to? Commented Jan 27, 2016 at 13:47
  • Also says its read only Commented Jan 27, 2016 at 13:54
  • Do you mean machine.config? Commented Jan 27, 2016 at 14:16
  • No I mean web.config. Basically I want to override the maximum request length from the application and not have to modify either the web.config, iis or machine.config as requires changes on each client. Commented Jan 27, 2016 at 14:18

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The Views folder has a web.config as part of the default setup to overwrite certain settings, can another one be added to somewhere similar maybe such as controllers to override it maybe? I tried on that web.config itself but didn't overwrite it
@user no, the Views/Web.config is only for the Razor compiler. It doesn't override anything in any way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.