Tsuna Sawada
Tsuna Sawada

Reputation: 349

Session for windows forms application in C#

Is there a session for Windows based applications for C# in order to record the details of log in in and log out for multiple users?

I tried to use declaring static variables, but it is not the same as a session.

Upvotes: 16

Views: 75033

Answers (2)

Sandman
Sandman

Reputation: 815

No, there are no session variables in a normal Windows application (the way there is in a web application). If you need logging for a Windows application I agree with the previously written comment to use some logging framework like log4net, NLog or something like that. Even using the Eventlogs can be an option, but I don't recommend it.

Upvotes: 1

sajanyamaha
sajanyamaha

Reputation: 3198

There is no concept of session variables in Windows Forms. You can do:

Create a static class that holds the user name and password and any other variables needed across the application.

In your case it would be something like:

public static class LoginInfo
{
    public static string UserID;
}

Now you can access the UserID simply from anywhere in your code:

MessageBox.Show(LogInfo.UserID);

Or set the values after login like:

LogInfo.UserID = TextBox1.Text;

Upvotes: 40

Related Questions