You are confusing expiration of session data with login session, and they’re not the same.
The performative way to do this is by defining an attribute that checks whether the SessionStore
whether or not it exists. If it does not exist, the login session expires:
public class VerificarSessaoExpiradaAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext contexto = HttpContext.Current;
// Verifica se existe um objeto definido na Session
var objeto = new DadosUsuario();
objeto = ((DadosUsuario)SessionStore.GetSessionValue("DadosUsuario"));
if (objeto == null)
{
filterContext.Result = new RedirectResult("~/Account/Login");
return;
}
base.OnActionExecuting(filterContext);
}
}
Then you decorate with it the Actions desired, or Controllers, or you can register the attribute globally:
[VerificarSessaoExpirada]
public ActionResult Index()
{
return Index();
}
The configuration is correct.
– Marcell Alves
Yes expires even if the user is working on the system
– Leonardo Macedo
Moving how? Session time is only renewed when the user makes a POST or GET or PUT, etc, to the server. If he is just working on the client part, the session might fall yes.
– Marcell Alves
Ha yes I understood, it is because this system was not I who made, I am giving maintenance, more all well! , thanks a lot for the help @Marcellalves
– Leonardo Macedo