6

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# ?

4

2 回答 2

3

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).

于 2011-07-31T09:50:27.537 回答
3

您可以在如下代码中设置 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();

我们在Rock RMS内容管理系统中执行此操作。

于 2014-05-10T19:53:41.273 回答