我想知道 session 锁定机制是如何工作的,以及我如何锁定变量及其各自的子对象以在服务器场环境中进行多次读取/独占写入。
场景 Web 场将使用 3 台 Windows 2003 服务器,每台服务器作为 Web 应用程序自己的应用程序域。 session 对象保存在 SQL Server 2005 上。 在我的网络应用程序中使用的对象如下:
MySampleClass = class
{
public string Id;
public Dictionary<string, CustomClass1> Data;
public List<string> Commands;
public CustomClass2 MoreData;
}
其中 customClass 1 和 2 是属于应用程序一部分的业务类。
现在在其中一个网页中,代码将如下所示:
Session["myObj"] = new MySampleClass();
在其他页面中:
MySampleClass = (MySampleClass)Session["myObj"];
//Is Session["myObj"] accessed in a multiple reader/exclusive writer mode? if so is it locking just the variable or the whole contents?
MySampleClass.Commands.Add("sample string");
MySampleClass.Commands.RemoveAt(0);
//More CRUD changes
//Are these changes available to other pages as soon as I finish the CRUD changes?
如果您需要更多详细信息,请告诉我
最佳答案
看看here在锁定 session 存储数据下。基本上,除非您的页面表示它需要只读 session 访问权限,否则该 session 将锁定在数据库上,并且该 session 的其他调用者将以 1/2 秒的间隔进行轮询,直到它被解锁。
关于c# - Asp.net: session 如何在服务器场环境中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1528701/