Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net配置文件中存储名称-值对_C#_Asp.net - Fatal编程技术网

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;