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.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With