Web.configファイルにはWebアプリケーションを実行するときにDebugモードかReleaseモードかによっていくつかのエントリがあります。ローカル、私は別のappSettingsを取るしたい。Web.Debug.configとローカルホストのWebアプリケーションを実行しているWeb.Release.config
たとえば、Web.Debug.config appSettingsに次のエントリがあるとします。
<add key="MyServiceUrl" value="http://my-test-site:8080/" />
そしてまた、私は私のWeb.Release.configでこれを持っている:
<add key="MyServiceUrl" value="http://my-prod-site:80/" />
私は私のWeb.Config、Web.Debug.ConfigとWeb.Release.Configそうに応じて設定する必要がありますどのようにモードは私のアプリケーションをローカルで実行します(デバッグ - すべてのCPU対リリース - すべてのCPU)、それは正しいものですか?
現時点では、キーと値の唯一のペアは、Visual Studioで[デバッグ]または[リリース]を選択するかどうかにかかわらず、メインWeb.Configのものです。
どうすればこのような動作を設定できますか?
EDIT
これは、私はこれは私がこれは私が持っているかであるWeb.Debug.config
<appSettings>
<add key="MyServiceUrl" value="http://my-test-site:8080/" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
を定義している方法ですWeb.configファイル
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
を定義している方法です定義済みWeb.Release.config
<appSettings>
<add key="MyServiceUrl" value="http://my-prod-site:8080/" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
012私はこのようにそれを呼び出す
public static string GetAppSetting(string settingKey)
{
if (string.IsNullOrEmpty(settingKey))
throw new System.ArgumentException("Cannot fetch a setting for a null/empty setting key.");
return ConfigurationManager.AppSettings[settingKey];
}
:
最後に、私のコードでは、私は次のような方法持っ 文字列の設定を= GetAppSetting( "MyServiceUrl");それはweb.Release.configでメインのWeb.config
_
または、次のようにしてください:_xdt:Transform = "Insert" _ –