简体   繁体   English

.NET无法正确读取web.config?

[英].NET doesn't read properly web.config?

I have 我有

   <system.web>
        <httpRuntime maxRequestLength="500000000"  />
    </system.web>

But when I read web.config via 但是当我通过浏览web.config时

 Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

            HttpRuntimeSection section =
              (HttpRuntimeSection)config.GetSection("system.web/httpRuntime"); 

I see 4096 value for maxRequestLength !! 我看到maxRequestLength值为4096 !!

How it could be?? 它怎么可能? Thanks for any clue! 谢谢你的任何线索!

PS It is ASP .NET MVC3 Razor project PS它是ASP .NET MVC3 Razor项目

There are a number of things to consider: 有许多事情需要考虑:

  • Is your <system.web> element a direct child of the <configuration> element? 您的<system.web>元素是<configuration>元素的直接子元素吗?
  • Is your web.config file in the root of your IIS Application Scope root? 您的web.config文件是否位于IIS Application Scope根目录的根目录中?
  • Is the <httpRuntime> element locked in the "root" .config file so values can't be overridden by other config files? <httpRuntime>元素是否锁定在“root”.config文件中,因此其他配置文件不能覆盖这些值?

If you're using IIS then I recommend using the Configuration editor to investigate configuration precedence. 如果您使用的是IIS,我建议使用配置编辑器来调查配置优先级。

My guess is that 500,000,000 Kb is above the maximum value for the maxRequestLength property, so it's being assigned its default value (4,096). 我的猜测是500,000,000 Kb高于maxRequestLength属性的最大值,因此它被分配了默认值(4,096)。 The documentation does not say what's the maximum value that maxRequestLength can take, but my guess is 20,97,151 Kb because that's roughly equal to 2^31 bytes, the maximum value that int can store. 文档没有说明maxRequestLength可以采用的最大值是多少,但我的猜测是20,97,151 Kb,因为它大约等于2 ^ 31字节,即int可以存储的最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM