Web.config文件的appSettings:复杂的值复杂、文件、Web、config

由网友(心疤i)分享简介:时的Web.config的的appSettings节只能够存储简单的字符串是这样的?Is Web.config's appSettings section only capable of storing simple strings like this?时的Web.config的的appSettings节只能够存储简单的字符串是这样的?

Is Web.config's appSettings section only capable of storing simple strings like this?

   <appSettings>
     <add key="OKPage" value="http://mysite.com/okpage.html" />
   </appSettings>

或者我可以有更复杂的价值观如CDATA或嵌套值?如果没有,这是在Web.config中唯一的地方来存储自定义设置?谢谢

or I can have more complex values like CDATA or nested values? If not, is this the only place in Web.config where to store custom settings? Thanks

推荐答案

您可以做任何XmlSerializable类的设置。

You can make any XmlSerializable class as a setting.

我回答到这里了类似的问题:ApplicationSettings在ASP.NET 也有一个示例项目连接。

I answered to the similar question here: ApplicationSettings in ASP.NET Also there is a sample project attached.

下面是从我的配置文件中的设置的一个例子:

Here is an example of the settings from my config file:

<setting name="MyEndPoints"
          serializeAs="Xml">
  <value>
    <ArrayOfEndPoint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <EndPoint>
        <HostName>10.40.10.9</HostName>
        <Port>22634</Port>
      </EndPoint>
      <EndPoint>
        <HostName>10.40.10.9</HostName>
        <Port>22635</Port>
      </EndPoint>
    </ArrayOfEndPoint>
  </value>
</setting>

自定义类设置:

Custom class for settings:

public class EndPoint
{
    public string HostName { get; set; }

    public int Port { get; set; }
}
阅读全文

相关推荐

最新文章