私のasp.net Webアプリケーションでは、Cache.Soを使用して、別のマシンまたは同じPCで同じユーザー名から複数のユーザーがログインするのを防ぎたいのですが、Global.asax.asページで、
私はこの行を置きます...
protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
if (Session["user"] != null) // e.g. this is after an initial logon
{
string sKey = (string)Session["user"];
string sUser = (string)HttpContext.Current.Cache[sKey];
}
}
そして私のページのログイン送信ボタンをクリックして、
string userName=uName.Text;
string passWord=pwd.Text;
string sKey = uName.Text;
string sUser = Convert.ToString(Cache[sKey]);
if (sUser == null || sUser == String.Empty)
{
TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null);
Session["user"] = TextBox1.Text.Trim();
if (userName.Equals(db_userName) && passWord.Equals(db_password))
{
Response.Write("Welcome " + userName);
}
else
{
Response.Write("Invalid Login");
}
}
else
{
Response.Write("<Marquee><h1><font color=red>ILLEGAL LOGIN ATTEMPT!!!</font></h1></marquee>");
return;
}
しかし、アプリケーションを実行すると、Application_PreRequestHandlerExecute イベントで Session state is not available in this context エラー メッセージが発生しています...
ここで何が問題なのかわかりません...だから、この問題から抜け出すために私を導いてください...
または、これの代わりに別の良いアプローチを教えてください...