2009-09-01 15 views
1

私は、私がのConfigurationSection、のConfigurationElementとをConfigurationElementCollectionを使用することが出来るのです道を間違って何かをしていない限り、そのように私の構成セクションをフォーマットするために私が必要になります。web.configファイルのカスタムのConfigurationSection、不要な冗長性

<serviceAuthorization> 
    <credentials> 
     <login username="system" password="password" mode="include"> 
      <services> 
       <service type="AxeFrog.Mobile.Service.Security.AuthenticationService, AxeFrog.Mobile.Service" /> 
       <service type="AxeFrog.Mobile.Service.Security.AnotherService, AxeFrog.Mobile.Service" /> 
      </services> 
     </login> 
     <login username="test" password="pass" mode="exclude" /> 
    </credentials> 
</serviceAuthorization> 

I私はフォーマットでもう少し言いたいことがあればもっと好むだろう。

<serviceAuthorization> 
    <login username="system" password="password" mode="include"> 
     <service type="AxeFrog.Mobile.Service.Security.AuthenticationService, AxeFrog.Mobile.Service" /> 
     <service type="AxeFrog.Mobile.Service.Security.AnotherService, AxeFrog.Mobile.Service" /> 
    </login> 
    <login username="test" password="pass" mode="exclude" /> 
</serviceAuthorization> 

設定セクションのXMLを取得して、それを自分で読む方法はありますか?

string docName=System.Web.HttpContext.Current.Server.MapPath("Web.config"); 
XmlDocument configDoc = new XmlDocument(); 
configDoc.Load(docName); 

をしてからconfigDocから作業:

答えて

1

あなたはSystem.Configuration.IConfigurationSectionHandlerを実装し、それを構成することができます。

<section name="serviceAuthorization" type="[your-type]"/> 

次に、あなたがあなたの全体sectionXmlNodeとして取得し、カスタムスキーマを解析することができます。

編集:これは非推奨です。ここにはnew wayが1つあります。

+0

私が理解しているように、IConfigurationSectionHandlerは非推奨になっています –

+0

あなたは絶対に正しいです。私はそれを私の答えに加えました。 –

0

さて、あなたはたとえば、行うことができます。

+1

私はそのルートを認識しています。私はちょうど少し原油のために何かを望んでいた。 –

関連する問題