private ActionResult CerrarSesion() { var rolUsuario = string.Empty; var userData = HttpSessionContext.CurrentAccount(); if (userData != null) { rolUsuario = userData.UserName; } var urlSignOut = string.Empty; FormsAuthentication.SignOut(); System.Web.HttpContext.Current.Session.Abandon(); System.Web.HttpContext.Current.Session.Clear(); urlSignOut = string.Format("{0}", System.Web.Security.FormsAuthentication.LoginUrl); return(Redirect(urlSignOut)); }
public ActionResult Login(LoginViewModel model, string returnUrl = null) { try { var oLoginDto = new LoginDto(); oLoginDto.v_UserName = model.Username; oLoginDto.v_Password = model.Password; var result = _securityBL.ValidateAccess(oLoginDto); if (result != null) { var sessionModel = new SessionModel(); var token = result.Token; sessionModel = _securityBL.UserAccess(result.SystemUserId, token); sessionModel.Pass = oLoginDto.v_Password; sessionModel.Token = token; FormsAuthentication.SetAuthCookie(sessionModel.UserName, false); HttpSessionContext.SetAccount(sessionModel); } else { ModelState.AddModelError("", "Contraseña o identificador de usuario incorrectos. Escriba la contraseña y el identificador de usuario correctos e inténtelo de nuevo."); return(View(model)); } } catch (Exception ex) { ModelState.AddModelError("", "Error al procesar la solicitud."); return(RedirectToAction("Login", "IngresoSistema")); } return(RedirectToLocal(returnUrl)); }