[英]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 property) "httpRuntime maxRequestLength" in ASP.NET with C# as code behind 如何以C#作为代码在ASP.NET中以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength”
is there any way to set values in web.config
through C# ? 有什么办法可以通过C#在
web.config
设置值?
You can set the web.config's maxRequestLength property in code like this: 您可以通过如下代码设置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();
We do this exact thing in our Rock RMS content management system. 我们在Rock RMS内容管理系统中做到这一点 。
Yes, you can set it in the web.config
是的,您可以在
web.config
设置
Just set it in the web.config
under the <system.web>
section. 只需在
<system.web>
部分下的web.config
进行设置即可。 In the below example I am setting the maximum length
to 2GB
在下面的示例中,我将
maximum length
设置为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
). 请注意,
maxRequestLength
以KB's
为单位设置,最大可设置为2GB( 2079152 KB's
)。 But default file size limit is (4MB)
. 但是默认文件大小限制为
(4MB)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.