我在锁定 asp.net 页面时遇到问题。我们有一个用户个人资料页面,我们需要为首先打开它的用户锁定该页面。详细信息如下,数据库中有很多用户配置文件记录,我们将记录号传递给查询字符串以打开特定页面。用户单击网格中的链接按钮并以只读模式打开记录。有一个编辑按钮,可以启用所有控件,并在用户单击后使其可用。任务是将记录锁定给首先单击编辑按钮的用户。

除此之外,还有很多场景,比如用户可以从页面导航或者他可以在两者之间关闭页面。在这些情况下,其他用户应该可以使用该记录。
请给我一些可能的方法或如何解决这个场景的例子。

提前致谢

最佳答案

由于您提到的所有原因,我认为这是一个非常糟糕的主意,但如果我必须这样做,我会做的是使用 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 缓存自动“解锁”记录。所以你可以免费获得这一切。

关于c# - 为用户锁定 asp.net 中的页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7225195/

10-17 02:37