2009-03-27 4 views

答えて

1

Mattの答えは微調整のカップルと、かなり多くあります...ラインが、何かのようにこの行を取ってはいけません。

あなたが構成コード自体の外にそれを持って満足している場合は、あなたのプロバイダ構成を拾っしたら、あなたは自分のプロバイダクラスから直接メインの接続文字列セクションに話すことができます。

var provider = ConfigurationManager.GetSection("ProviderConfiguration") 
       as ProdviderSettingsSection; 

ConnectionString connStr = 
    WebConfigurationManager.ConnectionStrings[provider.ConnectionString]; 

プロバイダにすべての情報を入力したい場合は、プロパティのバッキングフィールドが必要です。

1

メインアプリケーション設定の設定を読み込むカスタム設定要素を作成できます。

public class ProviderConfiguration : ConfigurationSection 
{ 
    #region Constructors 
    public ProviderConfiguration() { } 
    #endregion 

    #region Public Properties 
    [ConfigurationProperty("ProviderConnection")] 
    public ProvderSettingsConfigElement ProvderConnection 
    { 
     get { return (ProvderSettingsConfigElement)this["ProviderConnection"]; } 
    } 

    #endregion 
} 

public class ProvderSettingsConfigElement : ConfigurationElement 
{ 
    #region Constructors 
    public ProvderSettingsConfigElement() { } 

    public WebSecuritySettingsDataProviderElement(string name, string type) 
    { 
     ConnectionString = ConfigurationManager.Get("mainAppConnString"); 
    } 

    #region Public Properties 
    [ConfigurationProperty("connectionString")] 
    public string ConnectionString{get; set;} 

} 
関連する問題