0
信頼できるユーザカウンタを実装したいと思います。現在、私はセッション変数を使用しています。ここで私の実装を見て:匿名ユーザとログインユーザのカウント -
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["OnlineUsers"] = 0;
Application["LoggedInUsers"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
Application.Lock();
if ((int)Application["OnlineUsers"] > 0)
{
Application["OnlineUsers"] = (int) Application["OnlineUsers"] - 1;
}
Application.UnLock();
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Application.Lock();
Application["LoggedInUsers"] = (int)Application["LoggedInUsers"] + 1;
Application.UnLock();
}
protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
Application.Lock();
if ((int)Application["LoggedInUsers"] > 0)
{
Application["LoggedInUsers"] = (int) Application["LoggedInUsers"] - 1;
}
Application.UnLock();
}
このアプローチの欠点はよく知られています。私はもっと正確なものを見つけることができませんでした。私を助けてくれますか?
私は知っていますが、匿名ユーザーをそのように数える方法はありますか? – Peter
「アカウント」がないのに、匿名ユーザーに一意のセッションIDを与えることはできます。 – Larsenal
あなたは私にそれをするためのヒントを教えてもらえますか? – Peter