保存CookieCollection
1、如何将CookieCollection保存进数据库呢?
2、并从数据库获取出来还原成CookieCollection类型呢?
注:保存成本地文件也行。
------解决方案--------------------public void SerializeObject(object o,string path)
{
System.Runtime.Serialization.IFormatter obj = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream oS = new FileStream(path,FileMode.Create,FileAccess.Write,FileShare.Write);
obj.Serialize(oS,o);
oS.Close();
oS = null;
o = null;
return ;
}
//
public object DeserializeObject(string path)
{
if(!File.Exists(path))
return null;
FileStream oS = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.None);
System.Runtime.Serialization.IFormatter obj = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object o;
try
{
o = obj.Deserialize(oS);
}
catch(
System.Exception e)
{
throw (e);
}
finally
{
oS.Close();
oS= null;
obj = null;
}
return o;
}