如果我将 xml 文件(名称-> 值)的内容存储在会话集合中,那么在另一个页面上访问它的最佳方式是什么(即不是运行以下脚本的页面)。
它只是在我要访问集合的每个页面上创建一个新的 SessionStateItemCollection 实例的工作吗?
System.Xml.XmlDocument oXmlDoc = new System.Xml.XmlDocument();
oXmlDoc.Load(Server.MapPath("xml.xml")); //load XML file
XmlNode root = oXmlDoc.DocumentElement;
SessionStateItemCollection PSess = new SessionStateItemCollection(); //session collection
for (int x = 0; x < root.ChildNodes.Count; x++) //loop through children and add to session
{
PSess[root.ChildNodes.Item(x).Name] = root.ChildNodes.Item(x).InnerText; //add xml values to session
}