开发者

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

How to programmatically set (using GET SET开发者_JAVA技巧 property) "httpRuntime maxRequestLength" in ASP.NET with C# as code behind

is there any way to set values in web.config through C# ?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜