当前位置: 代码迷 >> ASP.NET >> 保存CookieCollection解决方案
  详细解决方案

保存CookieCollection解决方案

热度:4463   发布时间:2013-02-26 00:00:00.0
保存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; }
  相关解决方案