私が見たカスタム構成のすべての例で、データを格納するために要素を使用する人はいないようです。
<data name="1">
<server>aServer</server>
<ip>anipaddress</ip>
</data>
これは実際に可能ですか?
私は次のような属性を使用できることを知っています:
<data name="1" server="aServer" ip="anipaddress"/>
TIA
私が見たカスタム構成のすべての例で、データを格納するために要素を使用する人はいないようです。
<data name="1">
<server>aServer</server>
<ip>anipaddress</ip>
</data>
これは実際に可能ですか?
私は次のような属性を使用できることを知っています:
<data name="1" server="aServer" ip="anipaddress"/>
TIA
ConfigurationElement.DeserializeElementのデフォルトの実装では、タイプXmlNodeType.Text
orのノードがサポートされておらず、次のエラー メッセージとともに がXmlNodeType.CDATA
スローされます。ConfigurationErrorsException
The configuration section cannot contain a CDATA or text element.
したがって、要素のテキスト コンテンツを使用して情報を格納するには、ConfigurationElement.DeserializeElement
メソッドをオーバーライドします。
はい、できます。
<configuration>
<configSections>
<sectionGroup name="pageAppearanceGroup">
<section
name="pageAppearance"
type="Samples.AspNet.PageAppearanceSection"
allowLocation="true"
allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<pageAppearanceGroup>
<pageAppearance remoteOnly="true">
<font name="TimesNewRoman" size="18"/>
<color background="000000" foreground="FFFFFF"/>
</pageAppearance>
</pageAppearanceGroup>
</configuration>
次に、変数にアクセスします
Samples.AspNet.PageAppearanceSection config = (Samples.AspNet.PageAppearanceSection)System.Configuration.ConfigurationManager.GetSection(
"pageAppearanceGroup/pageAppearance");
Response.Write("<h2>Settings in the PageAppearance Section:</h2>");
Response.Write(string.Format("RemoteOnly: {0}<br>",
config.RemoteOnly));
etc....
このリンクを確認してください http://msdn.microsoft.com/en-us/library/2tw134k3.aspx