2011-02-10 4 views
3

저는 ASP.NET 웹 응용 프로그램에서 작업하는 10 인 팀의 일원이지만 위성 사무실의 유일한 개발자입니다 (본사와 다른 도메인). Web.config에서 웹 응용 프로그램을 내 팀에서 사용하는 다른 모든 사람들과 다른 특정 도메인 (<identity> 요소 및 데이터베이스 연결 문자열 변경)에서 작동하도록 변경해야합니다.소스 제어에서 로컬 Web.config를 쉽게 변경할 수 있습니까?

원본 Web.config 파일을 변경할 수 없습니다. 원래 Web.config 파일은 내 팀원 모두를 망칠 수 있기 때문입니다. MsBuild Web.config 변환은 유망스럽게 보였지만 웹 응용 프로그램을 배포하는 경우에만 작동합니다 (IIS를 내 응용 프로그램의 루트 디렉터리로 가리키고 있음). <TransformXml> 빌드 단계를 수동으로 실행했지만 로컬 Web.config 파일을 덮어 쓰지 않습니다. (액세스 거부 오류)

로컬 Web.config 파일을 몇 가지 선택적으로 변경하려면 어떻게해야합니까? 소스 컨트롤에 무엇이 수정되어 있습니까?

답변

0

소스 제어 기능을 수정하지 않는 솔루션에 대해 모르겠다.

Global.asax 조건 설정 :

void Session_Start(object sender, EventArgs e) 
{ 
    if (HttpContext.Current.Server.MachineName == "JOE" ){ 
    //my development machine 
    Application["mysetting"] = "myspecial setting"; 
    }else{ 
    // ... 
    } 
} 

여러 web.config

는 때때로 다른 서버에 대해 다른 web.config의이 그러나 여기 당신이이 상황에서 작동 할 수 있습니다 고려할 수있는 몇 가지 옵션이 있습니다 . 각각의 설정을 관리하는 것은 악몽이 될 수 있습니다. 따라서 스택 오버플로에 대한 질문 (찾을 수 없습니다! 죄송합니다)에서는 web.config.<setting>이 적절한 경우 기본 web.config 파일에 복사 붙여 넣기됩니다. asp.net managing multiple web.config files

public static string GetConnString() 
{ 
    string connString = ConfigurationSettings.AppSettings[GetConfigKey("database")]; 
    return connString; 
} 

public static string GetConfigKey(string baseKey) 
{ 
    string str = baseKey; 
    if (Dns.GetHostName().StartsWith("dinoch")) 
    { 
     str = str + "-dev"; 
    } 
    else if (Dns.GetHostName().StartsWith("prodsrvr")) 
    { 
     str = str + "-prod"; 
    } 
    return str; 
} 

<configuration> 
    <appSettings> 
    <add key="database-dev" value="server=(local)\vsdotnet;database=ASPXAPPS;Integrated Security=SSPI" /> 
    <add key="database-prod" value="server=(local)\vsdotnet;database=ASPXAPPS;Integrated Security=SSPI" /> 
    </appSettings> 
</configuration> 
1

가장 일반적인 섹션에서는 로컬 변경 사항이 connectionStrings입니다 필요로 :

Application/ 
    web.config.devserver 
    web.config.joebrown 
    web.config.production 

은 자세한 내용은 스택 오버플로에 게시물을 참조 동적

당신의 web.config 설정 변경 appSettings. 두 섹션 모두 .NET 프레임 워크는 별도의 파일로 저장됩니다.

그런 다음 소스 제어에서이 개별 파일을 유지하면됩니다 (무시, 한 번 가져 오기, 숨기기, 파일의 버전 관리 사용 중지, 소스 코드 사용). 예를 들어

,

<configuration> 
    <connectionStrings configSource="connections.config"/> 
</configuration> 


<connectionStrings> 
    <add name="Name" 
    providerName="System.Data.ProviderName" 
    connectionString="My;Personal;Connection;String;" /> 
</connectionStrings> 
+0

어떤 프로세스 가장에 대한 요소에 대한? (Web.config에만 들어갈 수있는 것) – Mike

관련 문제