2013-05-14 1 views
0

저는 ASP.NET 프로젝트에서 작업 중이며 web-app의 appSettings 섹션에 일부 설정을 추가해야합니다.여러 web.config 파일의 'appSettings'섹션을 나눕니다.

이제 이러한 설정이 커지면서 다른 파일로 구성하고 싶습니다. 나는이 같은 추가 내 응용 프로그램의 다른 디렉토리에 다른 Web.config의 파일을 만들었습니다

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    </system.web> 
    <appSettings> 
    <add key="settingKey" value="settingValue" /> 
    </appSettings> 
</configuration> 

을하지만 ConfigurationManager.AppSettings["settingKey"]를 통해 그들에 액세스하려고 할 때, 나는 null를 얻을.

다른 파일에서 설정을 분할 할 수 있습니까? 논리적으로 앱 설정 값을 구성하는 또 다른 방법이 있습니까?

+0

확인이 아웃 : http://stackoverflow.com/questions/11363121/connectionstring-management-for-many-projects-on-one-server-should-i-make-my-ow/11363291#11363291 –

답변

0

현재 실행중인 경로가 해당 디렉토리 내에있는 경우에만 디렉토리 내의 web.config 설정을 볼 수 있습니다. /Mydirectory/MyTestPage.aspx

당신은 볼 것 Web.config의 설정 : 그래서 예를 들면

: 당신이 좋아하는 페이지를로드하는 경우 /MyDirectory/web.config

에만 표시됩니다 여기 예를 들어 : /OtherDirectory/MyTestPage.aspx

이 게시물이 도움이 될 수 있습니다 : Creating a custom .config file in asp.net

0

을 나는이 내가 알고 너무 오래되었고 아마도 .NET Core에는 적용되지 않지만 Google과 비핵 코어 json 구성 파일을 사용하는 사람들에게는 아마 적용되지 않습니다. 다음은 내가 일반적으로하는 일입니다 ...

나는 web.config에서 모든 구성 설정을 취하기 위해 configSources을 사용합니다. 이것은 당신이 할 수있는

<configuration> 

    <log4net configSource="Config\debug\log4net.config" /> 
    <appSettings configSource="config\debug\settings.config" /> 
    <connectionStrings configSource="config\debug\connections.config" />  
    ...  
</configuration> 

... 당신이 (루트 web.config 파일) 구성 섹션에서 configSource를 선언 할 방법을 여기에 예를 들어 상대 위치를 제공하여 다른 파일에 특정 설정 섹션을 수행 할 수 있습니다 그 파일의 이름을 원하는대로 지정하십시오. 지정된 경로와 파일이 솔루션에 존재하는지 확인하십시오. 당신이 내가 볼 수 있습니다 위의 여기 사진에 ... 상대 경로는 프로젝트 루트를 기준으로, 지금은 ... settings.config 파일의 모습

enter image description here

<?xml version="1.0"?> 
<appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    <add key="foo" value="bar" /> 
</appSettings> 

있어 서로 다른 전개 환경에 대해 두 가지 다른 경로를 제공했기 때문에 분명히 내 conection 문자열과 설정이 프로덕션 환경에서 다르기 때문입니다. 응용 프로그램이 디버그 또는 릴리스 모드에 있는지 여부를 올바른 설정 파일을 사용할 수 있도록

은 그럼 당신은 ... 구성 변환을 사용할 수 있습니다

이것은 Web.Debug.config 파일의 모습입니다 enter image description here

..

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <log4net configSource="Config\debug\log4net.config" xdt:Transform="Replace" /> 
    <appSettings configSource="config\debug\settings.config" xdt:Transform="Replace" /> 
    <connectionStrings configSource="config\debug\connections.config" xdt:Transform="Replace" /> 
</configuration> 

출시 버전은 거의 동일합니다.꽤 많이 년대 configSource attributes.And에 제공되는 경로를 교체합니다. 같은 system.serviceModel 아이 요소의 많은으로 configSource 설정을 지원하는 다른 Web.config의 요소가있다.

관련 문제