Chandra sekhar
Chandra sekhar

Reputation: 167

Storing user details in application variable

How to store some 100 users details (username) in Application variable?I know how to use session but i dont know how to use Application variable and how to store in global.asax file?

Upvotes: 2

Views: 12842

Answers (2)

Kirill Bestemyanov
Kirill Bestemyanov

Reputation: 11964

Using of Application is absolutely like using Session. But this value are shared for all users.

Update in 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;
}

Upvotes: 3

Alex
Alex

Reputation: 35409

var users = new List<string>(){
    "mary", "bob"
};
HttpContext.Current.Application["users"] = users;

Upvotes: 3

Related Questions