1、如何将CookieCollection保存进数据库呢?2、并从数据库获取出来还原成CookieCollection类型呢?注:保存成本地文件也行。

解决方案 »

  1.   

    意思就是说怎么把Cookie保存下来,并如何使用,就没有人会吗???
      

  2.   

    可以,用序列化保存到本地文件或stream中,然后读顾bytes保存到数据库.
      

  3.   

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