0

我们将 asp.net html 表存储在会话中,它的工作文件带有 InProc 会话状态。

当我们使用状态服务器时,序列化从会话中获取表对象存在问题。

我尝试使用无法完成的 belo 代码...

Table table = null;
Session["table"] = tableToJson(table); 
table = jsonToTable(Session["table"]);               

 private string tableToJson(Table obj)
    {
       //Formatting.Indented,  new JsonSerializerSettings() {ReferenceLoopHandling = ReferenceLoopHandling.Serialize}
     //  return JsonConvert.SerializeObject(obj,Formatting.Indented,  new JsonSerializerSettings() {ReferenceLoopHandling = ReferenceLoopHandling.Serialize});
        //return JsonConvert.SerializeObject(obj);
       // return JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings() { PreserveReferencesHandling = PreserveReferencesHandling.All });

        StringBuilder sb = new StringBuilder();
        HtmlTextWriter tw = new HtmlTextWriter(new StringWriter(sb));
        obj.RenderControl(tw);
        return tw.InnerWriter.ToString();
    }
    private Table jsonToTable(object obj)
    {
        string serializedData = (string)obj;
        serializedData = serializedData.Replace("<table", "<table runat=\"server\"");
        Control tbl = Page.ParseControl(serializedData);
        return tbl as Table;            
        //var serializer = new XmlSerializer(typeof(Table));
        //var reader = new XmlTextReader(new StringReader(serializedData));
        //return (Table)serializer.Deserialize(reader);

        //string o = (string)obj;
        //Table tbl = (Table)Newtonsoft.Json.JsonConvert.DeserializeObject(o, typeof(Table));
        //return tbl;
    }

看看 谢谢

4

0 回答 0