Web中Session的设置与获取:
public List<DevicesModel> GetDeviceDataList(string OrderID) { List<DevicesModel> dms = new List<DevicesModel>(); if (Session["DeviceList"] == null) { DevicesModel dm1 = new DevicesModel(); dm1.ID = 1; dm1.OrderID = "ORD0001"; dm1.DeviceType = "DTM"; dm1.Manufacturer = "CETE"; dm1.Model = "MC-202"; dm1.SerialNumber = "A-3042896"; dm1.Status = "Order Saved"; dms.Add(dm1); DevicesModel dm2 = new DevicesModel(); dm2.ID = 2; dm2.DeviceType = "DTM"; dm2.Manufacturer = "A&D"; dm2.Model = "UC-DCC-C"; dm2.SerialNumber = "B-1221-0012"; dm2.Status = "Order Saved"; dms.Add(dm2); DevicesModel dm3 = new DevicesModel(); dm3.ID = 3; dm3.DeviceType = "ATG"; dm3.Manufacturer = "A&D"; dm3.Model = "UA-BBL-C"; dm3.SerialNumber = "B-1001-0012"; dm3.Status = "Order Saved"; dms.Add(dm3); DevicesModel dm4 = new DevicesModel(); dm4.ID = 4; dm4.OrderID = "ORD0002"; dm4.DeviceType = "ATG"; dm4.Manufacturer = "CETE"; dm4.Model = "MC-232"; dm4.SerialNumber = ""; dm4.Status = "Order Saved"; dms.Add(dm4); Session["DeviceList"] = dms; } else { dms = (List<DevicesModel>)Session["DeviceList"]; } return dms; }
Session的清空:
public string ClearSession() { try { Session.Remove("DeviceList"); return "OK"; } catch (Exception ex) { return ex.Message.ToString(); } }
时间: 2024-12-08 14:41:28