2010-05-19 3 views
1

에서 액세스없는 ConfigurationSection, 그런 일 : 연결 문자열 이름 값은 web.config 파일에서 모듈 섹션에없는내가 Web.config를 매핑하는 구성 클래스가있는 ConfigurationElement

public class SiteConfigurationSection : ConfigurationSection 
    { 
     [ConfigurationProperty("defaultConnectionStringName", DefaultValue = "LocalSqlServer")] 
     public string DefaultConnectionStringName 
     { 
      get { return (string)base["defaultConnectionStringName"]; } 
      set { base["defaultConnectionStringName"] = value; } 
     } 

     [ConfigurationProperty("Module", IsRequired = true)] 
     public ModuleElement Module 
     { 
      get { return (ModuleElement)base["Module"]; } 
     } 
    } 

    public class ModuleElement : ConfigurationElement 
    { 
     [ConfigurationProperty("connectionStringName")] 
     public string ConnectionStringName 
     { 
      get { return (string)base["connectionStringName"]; } 
      set { base["connectionStringName"] = value; } 
     } 

     public string ConnectionString 
     { 
      get 
      { 
       string str; 
       if (string.IsNullOrEmpty(this.ConnectionStringName)) 
       { 
        str =//GET THE DefaultConnectionStringName from SiteConfigurationSection; 
       } 
       else 
        str = this.ConnectionStringName; 

       return WebConfigurationManager.ConnectionStrings[str].ConnectionString; 
      } 
     }  

    } 

의미하는 경우, 값이되어야한다 구성 섹션에서 읽습니다.

어떻게 수행하나요?

답변

0

이것은 섹션 태그의 이름에 따라 달라집니다.

var cs = 
    ((SiteConfigurationSection)WebConfigurationManager 
     .GetSection("mySectionTag")).DefaultConnectionString; 
+0

이것은 내가 물어 보지 않은 질문입니다. – shivesh

+0

@shivesh 바로 당신의 질문입니다. 나는 당신의 질문을 오해했습니다. –

+0

@shivesh - 내 마지막 코멘트는 귀하의 질문과 관련된 답변을 수정했음을 나타내는 것입니다. 검토하시기 바랍니다. –

관련 문제