How to manage Session with Session in C# desktop and non-web applications?

Asked

Viewed 357 times

5

I can’t find an example of using the Session object for desktop applications, all I find are for applications made in C# for the web with Asp, etc.

Does anyone know how to check if a user is authenticated in the program when opening it?

I know it’s possible to do this with the Session object, but I only find examples for the Web and I can’t implement a session check.

  • You’ve already solved your problem?

1 answer

2

Unable to work with Session in the same way as you work on the Web.

I recommend creating a static class with static properties(get and set). These properties will become available while the program is "running".

Example below.

Your class that manages the sessions can stay like this:

public static class SessaoApp
{

    public static int UsuarioId { get; set; }

    public static string UsuarioNome { get; set; }

    public static string Login { get; set; }

    public static string Email { get; set; }
}

In its implementation it would be

       seuTextBoxEmail = SessaoApp.Email;
       seuTextBoxLogin = SessaoApp.Login;
       seuTextBoxNome = SessaoApp.UsuarioNome;
       seuTextBoxUsuarioId = SessaoApp.UsuarioId;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.