Knowing how to get hold of the relevant webnodes user session can sometime be a little confusing, I agree!
In general:
If you are in a web context, use WAFContext.Session
If you are in a worflow context use WFContext.Session
If you do not know (or the code may run i both) you can use this method to determine the context:
WAFRuntime.Context
Possible values:
switch (WAFRuntime.Context) {
case WAFRuntimeContext.WebDialogue: return WAFContext.Session;
case WAFRuntimeContext.WebEdit: return WAFContext.Session;
case WAFRuntimeContext.WebVisit: return WAFContext.Session;
case WAFRuntimeContext.WebOther: return WAFContext.Session;
case WAFRuntimeContext.Workflow: return WFContext.Session;
case WAFRuntimeContext.Internal: return WAFRuntime.SystemSession;
default: break;
}
This is however a little slow and has some performance issues as webnodes takes a few milliseconds to determine the context. So try not to use WAFContext.Context or WAFContext.ContextSession too much.
If you are working within a content class and overriding a property or method just use
This will take the session that belongs to the instance of the content class, no matter which context was used to retrieve it. This is very fast and the recommened way to get hold of a session within a class.
Here is some existing documentation: (but I agree, it does not explain all of it)
http://developer.webnodes.com/long-running-tasks
http://developer.webnodes.com/working-with-content
Hope this helps!