【问题标题】: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”作为代码
【发布时间】:2011-10-16 20:25:17
【问题描述】:

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

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

【问题讨论】:

    标签: c# asp.net web-config code-behind httpruntime


    【解决方案1】:

    可以,可以在web.config中设置

    只需在<system.web> 部分下的web.config 中设置即可。在下面的示例中,我将maximum length 设置为2GB

    <httpRuntime maxRequestLength="2097152" executionTimeout="600" />
    

    请注意maxRequestLength 设置在KB's 中,最大可设置为2GB (2079152 KB's)。但默认文件大小限制为(4MB)

    【讨论】:

      【解决方案2】:

      您可以像这样在代码中设置 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-25
        • 1970-01-01
        • 1970-01-01
        • 2017-09-21
        • 2021-06-22
        • 2023-01-03
        相关资源
        最近更新 更多