简体   繁体   English

ASP.NET网页的.aspx.cs文件中的私有静态变量

[英]private static variables in .aspx.cs file of ASP.NET webpage

Since "static" variables are shared by all instances of a class, I was wondering if they're shared through out all open pages of the website? 由于“静态”变量由类的所有实例共享,我想知道它们是否在网站的所有打开页面中都共享?

For example: Let's say I have the following: 例如:假设我有以下内容:

 private static string SelectedName = "";

 protected void SendButton_OnClick(object sender, EventArgs e)
 {
     SelectedName = NameTextBox.Text;
     DisplayLabel.Text = SelectedName;
 }

 // ... other functions that depend on SelectedName's value

If two people open my page.. User #1 types in "Bob" in the name text box and hits send. 如果两个人打开我的页面,则用户#1在名称文本框中键入“ Bob”,然后单击“发送”。 User #2, in some other location, now opens the page. 现在,用户#2在其他位置打开页面。 Will they see "Bob" as the DisplayLabel's text? 他们会在显示标签上看到“鲍勃”吗?

Static variables have application scope. 静态变量具有应用范围。 Meaning that users can share data through statics, but only in a single worker process on a single server. 这意味着用户可以通过静态方式共享数据,但只能在单个服务器上的单个工作进程中共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM