잊지 않겠습니다.

web.config 및 app.config에서 수많은 xml을 보다보면 무엇을 보고 사용해야지 될지 모르게 될 때가 많다. -_-

지금까지는 조금 어색하게 사용하고 있었던 application config section에 대한 내용을 한번 정리해보자. 

Section group에 대한 예시는 다음과 같다. 
  
    
        
        
  
section group의 name을 정할 수 있고, 그렇게 되면 configuration에 section group의 이름이 들어갈 수 있다.
configSections에 section group이 지정되어있지 않으면, section not found라는 web.config error가 나타나게 된다. 

여기에서 section name과 permission의 경우에는 일반적인 type에 따라서 정해주면 되는데, 그것보다 더 중요한 것이 뒤에 나오는 type값이다.
class full name, assembly name 으로 구성이 되어 있는 것을 볼 수 있다. 이는 사용자 section을 만들었을 때에 중요한 항목이 되는데, 자신이 만들어준 ConfigurationSection을 상속받은 ConfigurationSection class를 이용해서 handling할 class를 지정해주어야지 된다. 

예를 들어 주로 사용하는 web service url group을 만들었을 때에는 다음과 같다. 

  
    
      http://localhost/MPSWS/HostedActiveDirectory/Service.asmx
      http://localhost/MPSWS/Hostedsharepoint2007/Service.asmx
      http://localhost/mpsws/hostedemail2007/service.asmx
      http://localhost/mpsws/hostedsignup/service.asmx
      http://localhost/mpsws/managedplans/service.asmx
      http://localhost/mpsws/Exchange2007ResourceManager/service.asmx
      http://localhost/mpsws/HostedMobility2007/service.asmx
      http://localhost/mpsws/ManagedEmail2007/service.asmx
      http://localhost/mpsws/managedplans/service.asmx
    
    
      http://localhost/MPSWS/HostedActiveDirectory/Service.asmx
      http://localhost/MPSWS/Hostedsharepoint2007/Service.asmx
      http://localhost/mpsws/hostedemail2007/service.asmx
      http://localhost/mpsws/hostedsignup/service.asmx
      http://localhost/mpsws/managedplans/service.asmx
      http://localhost/mpsws/Exchange2007ResourceManager/service.asmx
      http://localhost/mpsws/HostedMobility2007/service.asmx
      http://localhost/mpsws/ManagedEmail2007/service.asmx
      http://localhost/mpsws/managedplans/service.asmx
    
  
public sealed class WebServiceUrlCollection : ConfigurationSection
{
    private readonly XmlDocument xmlDoc = new XmlDocument();
    public Dictionary MapTable { get; private set; }

    public string GetValue(string key)
    {
        if (MapTable == null)
        {
            Create();
        }
        if(MapTable.ContainsKey((key)))
        {
            return MapTable[key.ToString()];    
        }
        else
        {
            return string.Empty;
        }
    }

    private void Create()
    {
        MapTable = new Dictionary();
        foreach (XmlNode node in xmlDoc.ChildNodes[0].ChildNodes)
        {
            MapTable.Add(node.Name, node.InnerText); 
        }
    }
    protected override void DeserializeSection(XmlReader reader)
    {
        xmlDoc.Load(reader);
        Create();
    }
}
Posted by Y2K
,