SESSION: System confuses users who access it simultaneously

1

When 2 users access the system at the same time, it somehow confuses users, not just the name, but their permissions too ...

I'm assigning the session after logging in to ActionFilter

public class UsuarioAttribute : ActionFilterAttribute

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    int idUsuario= new UsuarioNegocio().GetIdByExternalId(decodedToken.ExternalUserId.ToInt32());//Id vem de um token

    Usuario usuario = new UsuarioNegocio().GetById(idUsuario);

    filterContext.HttpContext.Session["Usuario"] = usuario;
}

And in BaseController I have the following method to retrieve the session:

public Usuario GetCurrentUser()
{
   return (Usuario)HttpContext.Session["Usuario"];
}

Has anyone had this problem with session?

    
asked by anonymous 04.02.2016 / 13:32

2 answers

1

This is the wrong way to persist user data in ASP.NET MVC session.

Alternatives to this are:

EDIT

You said in response that you are using OutputCache , which is a global resource. That is, the first user to create the cache will create Session information for everyone.

[HttpGet, OutputCache(NoStore = true, Duration = 1)]

It seems absurd, but it makes perfect sense, just because session data is also held by OutputCache .

    
04.02.2016 / 16:05
0

The problem was in the controller in the exit method, it was like this:

[HttpGet, OutputCache(NoStore = true, Duration = 1)]

I just left with the get and resolved (I can not explain the reason):

[HttpGet]
    
04.02.2016 / 17:32