代码之家  ›  专栏  ›  技术社区  ›  mas_oz2k1

ASP.NET:会话在服务器场环境中的工作方式

  •  3
  • mas_oz2k1  · 技术社区  · 16 年前

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

    脚本 Web场将使用3台Windows 2003服务器,每台服务器都作为Web应用程序的应用程序域。sesion对象保存在SQL Server 2005上。 要在我的Web应用程序中使用的对象如下:

    MySampleClass = class
    {
      public string Id;
      public Dictionary<string, CustomClass1> Data;
      public List<string> Commands;
      public CustomClass2 MoreData;
    }
    

    其中,customClass1和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?
    

    如果你需要更多的细节请告诉我

    2 回复  |  直到 12 年前
        1
  •  3
  •   nitzmahone    16 年前

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

        2
  •  0
  •   David d C e Freitas    12 年前

    还有一个详细的解释 "Session State Providers" on msdn .

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

    推荐文章