Asp.net:会话在服务器场环境中如何工作

发布于 2024-08-07 02:46:11 字数 950 浏览 2 评论 0原文

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

设想 Web 场将使用 3 台 Windows 2003 服务器,每台服务器都作为 Web 应用程序自己的应用程序域。会话对象保存在 SQL Server 2005 上。 在我的 Web 应用程序中使用的对象如下:

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?

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

I would like to know in how the Session locking mechanism work and how I can lock a variable and its respective child objects for multiple reads/exclusive write in a server farm environment.

Scenario
The web farm will use 3 Windows 2003 servers, each server as its own app domain for the Web application. The sesion object is saved on SQL Server 2005.
The object to use in my web app is at follows:

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

where customClass 1 and 2 are business classes that are part of the application.

now in one of the web pages, code will look like:

Session["myObj"] = new MySampleClass();

in other pages:

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?

let me know if you need more details

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙与沫 2024-08-14 02:46:11

请查看此处的“锁定会话存储数据”。基本上,除非您的页面表示需要只读会话访问,否则会话将锁定在数据库上,并且该会话的其他调用者将以 1/2 秒的间隔进行轮询,直到解锁。

Have a look here under Locking Session-Store Data. Basically, unless your page says it wants read-only session access, the session is locked on the DB and other callers for that session will poll at 1/2sec interval until it is unlocked.

阳光下的泡沫是彩色的 2024-08-14 02:46:11

msdn上的“Session State Providers”也有详细的解释

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

There is also a detailed explanation on "Session State Providers" on msdn.

It covers the algorithm and rules used when using out-of-process session state providers in ASP.NET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文