Web.config文件的appSettings:复杂的值 [英] Web.config appSettings: complex values

查看:409
本文介绍了Web.config文件的appSettings:复杂的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时的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.

我回答到这里了类似的问题:<一href="http://stackoverflow.com/questions/6289388/applicationsettings-in-asp-net/6289586#6289586">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; }
}

这篇关于Web.config文件的appSettings:复杂的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆