我认为这是一个非常糟糕的主意,因为你提到的所有原因,但如果我有做到这一点,我会做的就是使用ASP.NET缓存。
所以,这样的事情:
Cache.Add(someUniqueKeyForAUserProfile, theUserThatLockedTheRecord, null,
DateTime.Now.AddSeconds(120), Cache.NoSlidingExpiration, CacheItemPriority.Normal,
UnlockRecord)
private static void UnlockRecord(string key, object value, CacheItemRemovedReason reason) {
//This particular record went longer than 2 minutes without
//the user doing anything, do any additional cleanup here you like
}
然后在页面上,你可以这样做:
if (Cache[someUniqueKeyForAUserProfile] != theUserThatLockedTheRecord){
//Tell the user they can't access the page
}
这里的好处是,两分钟后,你会自动“解锁”记录通过使用内置的ASP.NET缓存。所以你可以免费获得所有这些。
需要考虑的事情:浏览器崩溃,会话超时,用户在离开办公桌,返回键等 –