我有大约 10 个会话变量,用于存储每个不同 10 个类别的文件下载计数。我不知道为什么?但是我设置为 Global.asax 的会话变量会自动重置。
因为,机器没有重新启动。文件下载的计数器仍然会重置。任何的想法?请建议我任何解决方案。
在 Global.asax 中:
void Application_Start(object sender, EventArgs e)
{
Application.Add("MGM",0);
Application.Add("PC",0);
Application.Add("NC",0);
Application.Add("TC",0);
Application.Add("PGC",0);
}
The *shortCode* parameter is name of Global Session from Global.asax file. that i am passing to get the counter and increment accordingly.
In Download.aspx.cs Page:
private int GetCount(string shordCode)
{
int count=0;
count = Convert.ToInt32(Application[shortCode]);
lock (Application[shortCode])
{
Application[shortCode] = ++count;
}
return count;
}
我应该将值存储在文本文件中并在一定计数后相应更新说 500。如果是怎么办?我们的同事说,如果假设有许多用户下载文件,并且如果两者都从文本文件中访问相同的值,那么可能会出现 cuncurency。我很困惑......!感谢帮助。