静的変数はユーザー セッション間で値を保持しますか?
2 つのボタンがある ASP.NET Web アプリケーションがあります。1 つは静的変数値を設定するためのもので、もう 1 つは静的変数値を表示するためのものです。
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 台のコンピューターから同時にログインしている 2 人のユーザーがいるとどうなりますか。ユーザー 1 が値を 100 に設定し、次にユーザー 2 が値を 200 に設定します。その後、ユーザー 1 が [値の取得] ボタンを呼び出します。彼は何を価値として見るでしょうか?