添加到会话ASP.NET C#

Sim*_*mon 1 c# asp.net session

我想添加一个会话["i"],结果更多

目前它只会显示一组结果

例如,School1 11/10/2011 14/11/2011 GCSE AAA

我想添加更多集,但它们似乎没有存储在Session中

例如

School1 11/10/2011 14/11/2011 GCSE AAA

School2 11/10/2012 14/11/2012 ALevels AAA

Education addResults = new Education(schoolName, fromDate, toDate , qualification , grades);

Session["i"] = (addResults );

//schoolarraylist.Add(addResults );

foreach (Education currentschool in schoolarraylist)
      {
         Session["i"] = currentschool.Schoollocation + "," + currentschool.Datefrom + "," + currentschool.Dateto + "," + currentschool.Qualifications + "," + currentschool.Grade + "<br />";

           string tmp = Session["i"].ToString();
           string[] sb = tmp.Split(',');
           string [] ii = new string[sb.GetUpperBound(0) + 1];

            for (int i = 0; i <= sb.GetUpperBound(0); i++)
                {
                    ib[i] = (sb[i]);
                }

            foreach (string j in ii)
                {
                    Response.Write(ii);
                }

            }
Run Code Online (Sandbox Code Playgroud)

Adi*_*dil 5

您可以将对象列表分配给会话,然后再将其取回.But you should not put data in seesion without need.对于每个用户,在服务器端维护会话,并且将数据放入会话中占用服务器的内存,这可能降低应用程序的性能.在使用它们之前,它值得阅读会话.

List<string> lst = new List<string>();

Session["i"] = lst;
Run Code Online (Sandbox Code Playgroud)

从会话对象获取列表.

List<string> lst = (List<string>)Session["i"];
Run Code Online (Sandbox Code Playgroud)