如何在配置文件中存储名称 asp.net 值对
本文关键字:asp net 值对 存储 配置文件 | 更新日期: 2023-09-27 18:32:14
可能的重复项:
在 asp.net 配置文件中存储通用词典?
我想在 asp.net 配置文件中保存名称-值对,我该怎么做?
定义一个可以保存键值数据的类,如下所示:
namespace Samples.AspNet.Profile
{
[Serializable]
public class KeyValue{
public Dictionary<string, Object> dict= new Dictionary<string, Object>();
}
}
初始化键值类型配置中的配置文件:
<profile defaultProvider="AspNetSqlProfileProvider">
<properties>
<add name="List"
type="Samples.AspNet.Profile.KeyValue"
serializeAs="Binary" />
</properties>
</profile>
现在,您可以添加如下值:
KeyValue data= new KeyValue ();
data.dict.Add("Contoso","value");
bookCart.CartItems.Add("Microsoft","value2");
Profile.List= data;