gpt4 book ai didi

c# - 添加到 session ASP.NET C#

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:43 25 4
gpt4 key购买 nike

我想添加一个具有更多结果的 session ["i"]

目前它只会显示一组结果

例如学校 1 11/10/2011 14/11/2011 GCSE AAA

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

例如

学校 1 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);
}

}

最佳答案

您可以将对象列表分配给 session ,然后再取回。 但是您不应该在不需要的情况下将数据放入 seesion。 session 在服务器端为每个用户维护,将数据放入 session 会占用服务器内存,这可能会降低应用程序的性能。值得一读sessions在使用它们之前。

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

Session["i"] = lst;

从 session 对象获取列表。

List<string> lst = (List<string>)Session["i"];

关于c# - 添加到 session ASP.NET C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13063317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com