读书人

保存CookieCollection解决方案

发布时间: 2012-01-10 21:26:50 作者: rapoo

保存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;}

读书人网 >asp.net

热点推荐