I am using the followign object in my asp.net page
private static Dictionary<string, List<Guid>> OpenNodes = new Dictionary<string, List<Guid>>();
//Page start
if(!OpenNodes.ContainsKey(Session.SessionID))
{
List<Guid> list = new List<Guid>();
OpenNodes.Add(Session.SessionID, list);
}
//User clicked on a node
Guid id = new Guid(e.Node.Value);
tmpList = OpenNodes[Session.SessionID];
tmpList.Add(id);
OpenNodes[Session.SessionID] = tmpList;
Is it agood practive or is there a similar ‘better’ way to achieve the same?
You should not replace
Sessionwith static fields.Sessionis much more flexible and less error-prone. You can easily make it work in Web farms (you can’t do that with static fields). You can consider replacing someApplicationvariables with static fields. It’s important to know that static fields don’t provide any thread safety mechanism out of the box and you should manually control (lock) them appropriately.