2010-05-18 27 views
4

我一直在收到「連接強行關閉」的錯誤,並在研究解決方案時,我看到了以下web.config選項對金錢的建議,目前這些選項並未在我的Web應用程序中設置。如何確定以下默認Web配置值?

在我更改它們之前,我想知道它們當前設置的是什麼。

有人可以告訴我如何從.NET代碼中讀取這些值,最好是VB.NET,儘管C#很好。

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

回答

6

這裏是MSDN頁,列出了每個值和默認值。

下面的代碼將打開的httpRuntime節programitcly

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; 

根據評論編輯。

當調用WebConfigurationManager.OpenWebConfiguration從MSDN

路徑 類型:System 的虛擬路徑的配置文件。如果爲null,則會打開根Web.config文件。

即使您沒有在您的web.config中定義的httpRuntime,它也是根Web.config,並返回。我已經測試過,沒有定義httpRuntime。

+0

嗯。這直接讀取web.config。我的web.config和我的machine.config沒有這些部分,但我希望有一些DEFAULT設置可以使用該框架進行查詢,即使我選擇不通過添加我的部分來覆蓋這些默認設置網頁配置。 – ChadD 2010-05-18 16:15:04

+1

@George看我的編輯。即使你沒有在web.config中定義它,它也會打開httpRuntime。 – 2010-05-18 16:21:17

2

MSDN documentation提供的含義和默認值這個:)

如果你有興趣在其他web.config價值/含義/默認值,先從<configuration> 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" 
/> 
-1

特定安裝的默認值存儲在machine.config文件中。要訪問這些值,您可以使用:

ConfigurationManager.OpenMachineConfiguration(); 

獲取配置。訪問這些值可能存在一些安全限制。

+0

不是我的downvote - 但實際上,文檔明確指出:「httpRuntime元素沒有明確定義在Machine.config文件或根Web.config文件中。「 – 2010-05-18 16:06:20

+0

你是對的,他們不是,我看了那裏 – ChadD 2010-05-18 16:07:13

+1

這不是懲罰 - 它是爲了標記一個帖子沒用,因爲帖子不正確,所以沒用。 – 2010-05-19 16:37:05