protected void btnLogout_Click(object sender, EventArgs e) { WebServiceLog objServiceLog = new WebServiceLog(); LoginRequest objRequest = new LoginRequest(); ResponseBase objResponse = null; objServiceLog.RequestTime = DateTime.Now; objServiceLog.ControllerName = this.GetType().Name; objServiceLog.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { objResponse = new ResponseBase(); if (HttpContext.Current.Session["UserId"] != null && HttpContext.Current.Session["CompId"] != null) { objRequest.UserID = Convert.ToString(HttpContext.Current.Session["UserId"]); DataSet ds = UserDAL.UserLogout(Convert.ToInt32(HttpContext.Current.Session["CompId"]), objRequest.UserID, Utility.GetClientIPaddress()); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0]["ReturnCode"].ToString() == "1") { objResponse.ReturnCode = "1"; objResponse.ReturnMessage = "User logout succesfully."; } else { objResponse.ReturnCode = "2"; objResponse.ReturnMessage = "Unable to logout."; } objServiceLog.RequestString = JSONHelper.ConvertJsonToString(objRequest); objServiceLog.ResponseString = JSONHelper.ConvertJsonToString(objResponse); objServiceLog.RequestType = ConstantMessages.WebServiceLog.Success; Utility.DestroyAllSession(); Response.Redirect("~/login.aspx", false); } else { objServiceLog.RequestString = JSONHelper.ConvertJsonToString(objRequest); objServiceLog.ResponseString = JSONHelper.ConvertJsonToString(objResponse); objServiceLog.RequestType = ConstantMessages.WebServiceLog.Validation; } } catch (Exception ex) { objServiceLog.ResponseString = "Exception " + ex.Message + " | " + ex.StackTrace; objServiceLog.RequestType = ConstantMessages.WebServiceLog.Exception; } finally { objServiceLog.ResponseTime = DateTime.Now; InsertRequestLog.SaveWebServiceLog(objServiceLog); } }
protected void btnLogout_Click(object sender, EventArgs e) { WebServiceLog objServiceLog = new WebServiceLog(); LoginRequest objRequest = new LoginRequest(); ResponseBase objResponse = null; objServiceLog.RequestTime = DateTime.Now; objServiceLog.ControllerName = this.GetType().Name; objServiceLog.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; try { objResponse = new ResponseBase(); if (HttpContext.Current.Session["UserId"] != null && HttpContext.Current.Session["CompId"] != null) { ActiveUsersCache objSession = new ActiveUsersCache(); List <ActiveUser> lstActiveUsers = new List <ActiveUser>(); if (Cache["ActiveUsers"] != null) { lstActiveUsers = (List <ActiveUser>)Cache["ActiveUsers"]; } objSession.KillSession(lstActiveUsers, Session.SessionID, null); objRequest.UserID = Convert.ToString(HttpContext.Current.Session["UserId"]); DataSet ds = UserDAL.UserLogout(Convert.ToInt32(HttpContext.Current.Session["CompId"]), objRequest.UserID, Utility.GetClientIPaddress()); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0]["ReturnCode"].ToString() == "1") { objResponse.ReturnCode = "1"; objResponse.ReturnMessage = "User logout succesfully."; } else { objResponse.ReturnCode = "2"; objResponse.ReturnMessage = "Unable to logout."; } objServiceLog.RequestString = JSONHelper.ConvertJsonToString(objRequest); objServiceLog.ResponseString = JSONHelper.ConvertJsonToString(objResponse); objServiceLog.RequestType = ConstantMessages.WebServiceLog.Success; Utility.DestroyAllSession(); //This is to delete all cookies from client web browser //HttpCookie myCookie = new HttpCookie("UserInfo"); //myCookie.Expires = DateTime.Now.AddDays(-1); //Response.Cookies.Add(myCookie); Response.Cookies["userid"].Expires = DateTime.Now.AddDays(-1); //End Response.Redirect("~/login.aspx", false); } else { objServiceLog.RequestString = JSONHelper.ConvertJsonToString(objRequest); objServiceLog.ResponseString = JSONHelper.ConvertJsonToString(objResponse); objServiceLog.RequestType = ConstantMessages.WebServiceLog.Validation; } } catch (Exception ex) { objServiceLog.ResponseString = "Exception " + ex.Message + " | " + ex.StackTrace; objServiceLog.RequestType = ConstantMessages.WebServiceLog.Exception; } finally { objServiceLog.ResponseTime = DateTime.Now; InsertRequestLog.SaveWebServiceLog(objServiceLog); } }