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

4

I can not find an example of using the Session object for desktop applications, all I encounter 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 that it is possible to do this with the Session object, but I can only find examples for the Web and I can not implement a session check.

    
asked by anonymous 24.06.2015 / 14:18

1 answer

1

You can not work with Session the same way you work on the Web.

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

Example below.

Your class that manages the sessions may look 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; }
}

Your implementation would be

       seuTextBoxEmail = SessaoApp.Email;
       seuTextBoxLogin = SessaoApp.Login;
       seuTextBoxNome = SessaoApp.UsuarioNome;
       seuTextBoxUsuarioId = SessaoApp.UsuarioId;
    
24.06.2015 / 14:56