アプリケーションレベルの文字列は、次のようにglobal.asaxファイルに保存できます 。Globalasax:
void Application_Start(object sender, EventArgs e)
{
Application.Lock();
Application["msg"] = "";
Application.UnLock();
}
そして、ページでは、「msg」変数を次のように取得します 。a.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string msg = (string)Application["msg"];
//manipulating msg..
}
ただし、オブジェクトのリストを文字列msgではなくアプリケーションレベルの変数として保存したいと思います。私はこれを試しました: Global.asax:
void Application_Start(object sender, EventArgs e)
{
Application.Lock();
List<MyClassName> myobjects= new List<MyClassName>();
Application.UnLock();
}
a.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
//here I want to get myobjects from the global.asax and manipulate with it..
}
では、List myobjectsをアプリケーションレベルの変数としてglobal.asaxに格納し、これを操作するにはどうすればよいでしょうか。
さらに、別の質問があり ます。global.asaxのグローバル変数が変更されたときにクライアント(ブラウザー)に通知を送信するにはどうすればよいですか?