【问题标题】:Asp.net: How session works in a server farm environmentAsp.net:会话如何在服务器场环境中工作
【发布时间】:2014-04-11 07:49:41
【问题描述】:

我想知道会话锁定机制是如何工作的,以及如何在服务器场环境中锁定变量及其各自的子对象以进行多次读取/独占写入。

场景 Web 场将使用 3 个 Windows 2003 服务器,每个服务器作为 Web 应用程序自己的应用程序域。会话对象保存在 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?

如果您需要更多详细信息,请告诉我

【问题讨论】:

    标签: c# asp.net session-state


    【解决方案1】:

    查看锁定会话存储数据下的here。基本上,除非您的页面说它需要只读会话访问,否则会话在数据库上被锁定,并且该会话的其他调用者将以 1/2 秒的间隔轮询,直到它被解锁。

    【讨论】:

    • 谢谢,只需要添加会话是基于字典的。
    【解决方案2】:

    "Session State Providers" on msdn上也有详细说明。

    它涵盖了在 ASP.NET 中使用进程外会话状态提供程序时使用的算法和规则。

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 2011-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多