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# ?
HttpRuntime maxRequestLength The default size is 4096 kilobytes (4 MB). Max value 2,147,483,647 kilobytes (~82 Terabyte).
The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks that are caused by users who post large files to the server.
You have to increase the maxRequestLength setting in web.
You can set the web.config's maxRequestLength property in code like this:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With