Check the size of`Sessions` on the server

Asked

Viewed 275 times

2

The following method is used in a web form application to store 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 as it will store various information that will be used in various parts of the application.

What is the best way to create Sessions?

Using class? What precautions should be taken in this approach?

Or Creating several Sessions 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 the excessive use of Sessions will overload the server memory!

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

You could do this via a web form application?

1 answer

1


No problem using objects in the session, actually recommended. C# is object oriented (remember?).

The use of individual keys in the session will depend on the data to be stored, ie, should make use of common sense. If you have an object with N properties that will use only 1 of these properties, why would you store the whole object? None. If you have an object with 10 properties and will only use 5 properties, 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 the size of the session, this will depend on the amount of memory available 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 tip: How to find out size of Session in ASP.NET from web application?

Browser other questions tagged

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