靜態變量是否在用戶會話中保留其值?多用戶ASP.NET Web應用程序中靜態變量的範圍
我有一個ASP.NET Web應用程序,我有兩個按鈕。一個用於設置靜態變量值,另一個用於顯示靜態變量值。
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
public static int customerID;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSetCustomerID_Click(object sender, EventArgs e)
{
customerID = Convert.ToInt32(TextBox1.Text);
}
protected void ButtonGetCustomerID_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(customerID);
}
}
}
雖然這部作品在單用戶環境中,會發生什麼事,如果有2個用戶同時從兩臺電腦,用戶1臺價值爲100,則用戶2臺的用戶後值200登錄1調用Get Value按鈕。他認爲價值是什麼?
見我的問題/答案:https://stackoverflow.com/questions/12642136/asp-net-static-classes-and-asp-net-sessions – BlueChameleon