c# - 在应用程序变量中存储用户详细信息

标签 c# asp.net

如何在 Application 变量中存储大约 100 个用户详细信息(用户名)?我知道如何使用 session ,但我不知道如何使用 Application 变量以及如何存储在 global.asax 文件中?

最佳答案

Application 的使用与使用 Session 完全一样。但这个值(value)是所有用户共享的。

更新 在 global.asax 中:

void Application_Start(object sender, EventArgs e)
{
    var userList = new List<string>();
    Application["UserList"] = userList;
}
void Session_Start(object sender, EventArgs e)
{
    var userName = Membership.GetUser().UserName;

    List<string> userList;
    if(Application["UserList"]!=null)
    {
        userList = (List<string>)Application["UserList"];
    }
    else
        userList = new List<string>();
    userList.Add(userName);
    Application["UserList"] = userList;
}

关于c# - 在应用程序变量中存储用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11888603/

相关文章:

asp.net - 将 mvc 4 降级/转换为 mvc 3

c# - Visual Studio 2010 C# 单行编译器

c# - 从字典键中获取值,而每个元素都是字符串

c# - KeyEventArgs.Key 到 char

asp.net - 使用 Asp.Net Owin Oauth 进行增量 Google OAuth

c# - 找出哪个控件触发了回发

c# - 为什么这个static bool不需要初始化呢?

c# - 将 Action<.., .., T > 作为没有预定义数量的 Action 参数的参数传递

asp.net - 如何使 Asp.net Gridview 标题和第一列卡住?

c# - 如何向标签添加加减号