编程语言
首页 > 编程语言> > 如何在ASP.NET中用C#编程设置(使用GET SET属性)“httpRuntime maxRequestLength”作为代码隐藏

如何在ASP.NET中用C#编程设置(使用GET SET属性)“httpRuntime maxRequestLength”作为代码隐藏

作者:互联网

如何在ASP.NET中用C#编程设置(使用GET SET属性)“httpRuntime maxRequestLength”作为代码隐藏

有没有办法通过C#在web.config中设置值?

解决方法:

您可以在以下代码中设置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内容管理系统中执行this exact thing.

标签:c,asp-net,web-config,code-behind,httpruntime
来源: https://codeday.me/bug/20190521/1147959.html