简体   繁体   English

序列化String-collection对象以存储在会话变量中

[英]Serialize String-collection object for storing in session variable

In my ASP.Net application, I'm storing a string collection in a Session variable. 在我的ASP.Net应用程序中,我将字符串集合存储在Session变量中。 It was working fine but now I want to change session settings from in-proc to Out Proc. 一切正常,但现在我想将会话设置从In-proc更改为Out Proc。 Now I'm having an issue that "Non-Serializable Object Stored in Session". 现在,我遇到一个问题:“会话中存储了不可序列化的对象”。 How can I serialize the Sting Collection object before assigning it to a session variable? 在将Sting Collection对象分配给会话变量之前,该如何序列化它? Please help. 请帮忙。

Session["SelectedItems"] =customerGroupsList.SelectedItemsCollection;

I want to change above line of code. 我想更改上面的代码行。

如果它实际上只是一个字符串集合对象,那么您可以使用下面的代码序列化它并将其存储为String:

        Session["SelectedItems"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(customerGroupsList.SelectedItemsCollection);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM