【问题标题】:How do I determine the following default web config values?如何确定以下默认 Web 配置值?
【发布时间】:2010-05-18 16:00:39
【问题描述】:

我遇到了“强制关闭连接”错误,在研究解决方案时,我看到了以下 web.config 选项的建议,这些选项目前未在我的网络应用程序中设置。

在更改它们之前,我想知道它们当前的设置。

有人可以告诉我如何从 .NET 代码中读取这些值,最好是 VB.NET,尽管 C# 很好。

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

【问题讨论】:

    标签: asp.net vb.net web-config


    【解决方案1】:

    这是MSDN 页面,其中列出了每个值是什么及其默认值。

    以下代码将通过程序打开 httpRuntime 部分

    Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
    object o = config.GetSection("system.web/httpRuntime");
    HttpRuntimeSection section = o as HttpRuntimeSection;
    

    此代码被发现here

    在 VB 中

    Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
    Dim o As Object = config.GetSection("system.web/httpRuntime")
    Dim section As HttpRuntimeSection = TryCast(o, HttpRuntimeSection)
    

    确保您正在使用/导入以下命名空间。

    System.Configuration;
    System.Web.Configuration;
    

    根据评论进行编辑。

    当从 MSDN 调用 WebConfigurationManager.OpenWebConfiguration

    路径 类型:System.String 配置文件的虚拟路径。如果为 null,则打开根 Web.config 文件。

    即使您的 web.config 中没有定义 httpRuntime,它也是根 Web.config,并且会被返回。我已经在定义和不定义 httpRuntime 的情况下对此进行了测试。

    【讨论】:

    • 嗯。这会直接读取 web.config。我的 web.config 和 machine.config 中没有这些部分,但是,我希望有可以使用框架查询的默认设置,即使我选择不通过在我的网络配置。
    • @George 看到我的编辑。即使您没有在 web.config 中定义它,它也会打开 httpRuntime。
    【解决方案2】:

    MSDN documentation 提供了它的含义和默认值:)

    如果您对其他 web.config 值/含义/默认值感兴趣,请从 &lt;configuration&gt; schema 开始并深入了解您所追求的内容。快速参考(.Net 4 值):

    <httpRuntime 
       executionTimeout="110"
       maxRequestLength="4096"
       requestLengthDiskThreshold="80"
       useFullyQualifiedRedirectUrl="false"
       minFreeThreads="8"
       minLocalRequestFreeThreads="4"
       appRequestQueueLimit="5000"
       enableKernelOutputCache="true"
       enableVersionHeader="true"
       requireRootedSaveAsPath="true"
       enable="true"
       shutdownTimeout="90"
       delayNotificationTimeout="5"
       waitChangeNotification="0"
       maxWaitChangeNotification="0"
       requestPriority="Normal"
       enableHeaderChecking="true"
       sendCacheControlHeader="true"
       apartmentThreading="false"
    />
    

    【讨论】:

      【解决方案3】:

      特定安装的默认值存储在machine.config 文件中。要访问这些值,您可以使用:

      ConfigurationManager.OpenMachineConfiguration();
      

      获取配置。访问这些值可能存在一些安全限制。

      【讨论】:

      • 不是我的反对意见 - 但实际上,文档明确指出:“httpRuntime 元素未在 Machine.config 文件或根 Web.config 文件中明确定义。”
      • 这不是惩罚 - 这是为了将帖子标记为无用。由于帖子不正确,因此没有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      相关资源
      最近更新 更多