How to programmatically set (using the GET SET property) "httpRuntime maxRequestLength" in ASP.NET with C # as code

How to programmatically set (using the GET SET property) "httpRuntime maxRequestLength" in ASP.NET with C # as the code for

is there any way to set values ​​in web.configvia c #?

+5
source share
2 answers

You can set the web.config maxRequestLength property in the code as follows:

Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "~" );
var section = (System.Web.Configuration.SystemWebSectionGroup)webConfig.GetSectionGroup("system.web");
section.HttpRuntime.MaxRequestLength = 10 * 1024; // 10 MB
webConfig.Save();

We do this exact thing in our Rock RMS content management system.

+3
source

Yes, you can set it to web.config

web.config <system.web>. maximum length 2GB

<httpRuntime maxRequestLength="2097152" executionTimeout="600" />

, maxRequestLength KB's, 2 (2079152 KB's). - (4MB).

+2

All Articles