How to programmatically set (using GET SET property) "httpRuntime maxRequestLength" in ASP.NET with C# as code behind
is there any way to set values in web.config
through C# ?
How to programmatically set (using GET SET property) "httpRuntime maxRequestLength" in ASP.NET with C# as code behind
is there any way to set values in web.config
through C# ?
Yes, you can set it in the web.config
Just set it in the web.config
under the <system.web>
section. In the below example I am setting the maximum length
to 2GB
<httpRuntime maxRequestLength="2097152" executionTimeout="600" />
Please note that the maxRequestLength
is set in KB's
and it can be set up to 2GB (2079152 KB's
). But default file size limit is (4MB)
.
您可以在如下代码中设置 web.config 的maxRequestLength属性:
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();