How to read system.web section from web.config

后端 未结 3 2083
轻奢々
轻奢々 2021-02-13 09:37

Should be simple, but whatever I try returns null:

const string key = \"system.web\";

var sectionTry1 = WebConfigurationManager.GetSection(key);

var sectionTry         


        
3条回答
  •  庸人自扰
    2021-02-13 09:52

    This worked for me:

    public Int32 GetmaxRequestLength()
    {
        // Set the maximum file size for uploads in bytes.
        var section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
        // return length converted to kbytes or return default value as specified
        return (Int32) Math.Round((decimal)(section != null ? (double)section.MaxRequestLength * 1024 / 1000 : 5.120), 2);
    }
    

提交回复
热议问题