Locking per ASP.NET session
This is just untested code, from the top of my head, but it may work?
// globally declare a map of session id to mutexes
static ConcurrentDictionary<string, object> mutexMap = new ConcurrentDictionary();
// now you can aquire a lock per session as follows
object mutex = mutexMap.GetOrAdd(session.SessionId, key => new object());
lock(mutex)
{
// Do stuff with the connection
}
You would need to find a way to clear old sessions out of the mutexMap
but that shouldn't be too difficult.