Verify session size on the server

2

The following method is used in a web form application to save logged-in user information:

public Usuario UsuarioLogado
{
    get
    {
        if (Session["Usuario"] != null)
            return (Usuario)Session["Usuario"];
        else
            return null;
    }
    set
    {
        Session["Usuario"] = value;
    }
}

In case I use a class because it will save various information that will be used in various parts of the application.

What is the best way to create Sessions ?

Using the class? What care should be taken in this approach?

Or Creating multiple% of individual%?

Session["ForcaTrocarSenha"] = usuario.FirstOrDefault().bit_altera_senha;
Session["SenhaAtual"] = usuario.FirstOrDefault().txt_senha.ToString();
Session["Login"] = usuario.FirstOrDefault().txt_login.ToString();
Session["IdUsuario"] = usuario.FirstOrDefault().int_id_usuario.ToString();

In my understanding, excessive use of Sessions will overwhelm server memory!

How can I check the memory consumption of the Sessions of an application on the server?

Would you like to do this via a web application form?

    
asked by anonymous 19.12.2014 / 15:00

1 answer

1

There is no problem with using objects in the session, it is actually recommended. C # is object oriented (remember?).

The use of individual keys in the session will depend on the data to be stored, that is, one should make use of common sense. If you have an object with N properties and you will only use 1 of these properties, why would you store the entire object? None. If you have an object with 10 properties and will only use 5, there will be no problem storing them individually, but the 'ideal' would be to create an object with only these 5 properties and store it in the session.

Regarding session size, this will depend on the amount of available memory and the configuration used. Remember that there are 4 session storage modes (InProc, StateServer, SQLServer and Custom). I recommend reading: Session-State Modes

As for memory consumption, you can try the following hint: How to find out ASP.NET session size from web application?

    
29.12.2014 / 04:13