2

私が見たカスタム構成のすべての例で、データを格納するために要素を使用する人はいないようです。

<data name="1">
<server>aServer</server>
<ip>anipaddress</ip>
</data>

これは実際に可能ですか?

私は次のような属性を使用できることを知っています:

<data name="1" server="aServer" ip="anipaddress"/>

TIA

4

2 に答える 2

0

ConfigurationElement.DeserializeElementのデフォルトの実装では、タイプXmlNodeType.Textorのノードがサポートされておらず、次のエラー メッセージとともに がXmlNodeType.CDATAスローされます。ConfigurationErrorsExceptionThe configuration section cannot contain a CDATA or text element.

したがって、要素のテキスト コンテンツを使用して情報を格納するには、ConfigurationElement.DeserializeElementメソッドをオーバーライドします。

于 2013-04-12T22:18:36.880 に答える
-1

はい、できます。

<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

于 2012-08-15T16:47:35.573 に答える