How about Devs, I am developing a Web forms application with asp.net, I can not make the session expire before 20 minutes, I have a login screen where when I authenticate I keep the authenticated user in a session variable, this I do so keep the session within the system (it is not the most correct way), the issue is that after 20 minutes of inactivity I returned to the login, the other is that for some reason if I am working within the system after 20 minutes I also take out of the system, how can I solve this, attached source code of the settings of how I manage the session:
web.config:
login screen:
protected void btnLogin_Click (object sender, EventArgs e) {
string sUsuario = tbUserName.Text;
string sPassword = tbPassword.Text;
DataSet dsUsuario;
if (!string.IsNullOrEmpty(sUsuario) && !string.IsNullOrEmpty(sPassword))
{
try
{
if (objControllerSeguridad.AutenticarUsuario(sUsuario, sPassword))
{
dsUsuario = objControllerSeguridad.DsReturn;
if (dsUsuario.Tables["Usuario"].Rows.Count > 0)
{
Session["usuario"] = dsUsuario.Tables["Usuario"].Rows[0]["USUARIO"].ToString();
Session["nombreUsuario"] = dsUsuario.Tables["Usuario"].Rows[0]["NOMBRE"].ToString();
Session["idRol"] = dsUsuario.Tables["Usuario"].Rows[0]["ID_ROL"].ToString();
Session["rol"] = dsUsuario.Tables["Usuario"].Rows[0]["ROL"].ToString();
Response.Redirect("~/", false);
}
else
{
FailureText.Text = "Usuario o Clave incorrecta.";
ErrorMessage.Visible = true;
return;
}
}
else
{
FailureText.Text = "Ocurrio un error, consulte con el administrador del sistema.";
ErrorMessage.Visible = true;
return;
}
}
catch (Exception ex)
{
log.LogError(ex.ToString(), ex.StackTrace);
}
}
}
And in the master page is where I control the user session variable that has not expired: protected void Page_Load (object sender, EventArgs e) { try { var sCookie = Request.Cookies ["Cookie"]. ToString ();
//if (Session["usuario"] == null || Session["idRol"] == null || String.IsNullOrEmpty(sCookie))
if (Session["usuario"] == null || Session["idRol"] == null)
{
Response.Redirect("~/Account/Login.aspx");
}else
BuildMenu(dxMenu, SqlDtsBanco);
if(dxMenu.SelectedItem != null)
Session["id_menu"] = dxMenu.SelectedItem.ToString();
}
catch (Exception ex)
{
Response.Redirect("~/Account/Login.aspx");
//Session.Abandon();
}
}
}