我有一个 ASP.NET (4.0) webforms 应用程序,我想知道在我的 web 应用程序中的用户之间共享数据时我有哪些选择。
最明显的解决方案是数据库表。但是还有其他选择吗?我已经阅读了有关“应用程序范围”的内容,但我不确定它是否对这种情况有用。
应用程序就是您要搜索的内容。
if (Application["CurrentUsers"] == null)
Application["CurrentUsers"] = 0;
Application["CurrentUsers"] += 1;
只是当前在线计数器的一个示例。
要对生命周期做出反应,请参阅global.asax
:
protected void Application_Start(object sender, EventArgs e)
{
Application["CurrentUsers"] = 0;
}
protected void Application_End(object sender, EventArgs e)
{
Application["CurrentUsers"] = null;
}
应用程序对象或将其存储在内存数据库中