C# 如何在asp.net配置文件中存储名称-值对
可能重复:C# 如何在asp.net配置文件中存储名称-值对,c#,asp.net,C#,Asp.net,可能重复: 我想在asp.net配置文件中保存名称-值对,如何才能做到这一点?定义一个可以保存键值数据的类,如: namespace Samples.AspNet.Profile { [Serializable] public class KeyValue{ public Dictionary<string, Object> dict= new Dictionary<string, Object>(); } } 感谢ans
我想在asp.net配置文件中保存名称-值对,如何才能做到这一点?定义一个可以保存键值数据的类,如:
namespace Samples.AspNet.Profile
{
[Serializable]
public class KeyValue{
public Dictionary<string, Object> dict= new Dictionary<string, Object>();
}
}
感谢ans,你能解释一下我们如何使用“Profile.List=data;”吗?因为我现在使用的是ProfileBase Profile=HttpContext.Current.Profile;profile.SetPropertyValue(“图像”,sc);正如您所见,我添加了一个配置文件
name=List
,其中保存的数据类型为Samples.AspNet.profile.KeyValue
,因此我们将List对象分配给KeyValue,或者您可以尝试profile.SetPropertyValue(“List”,数据)代码>是此格式(profile.SetPropertyValue(“List”,data);)我当前正在使用,但我想知道是否有一种方法可以使用(profile.List=data)而不是(profile.SetPropertyValue(“List”,data);)在profiles中插入数据是的,可以尝试,如果不能,则可以搜索。
<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;