protected void btnSave_Click(object sender, EventArgs e) { if (ValidateUser()) { UserBAL userBL = new UserBAL(); UserDom user = userBL.ReadUserByLoginId(LoginUser.UserName); if (user.UserTypeId == 2 || user.UserTypeId == 3) { DateTime lastloginDate = user.LastLoginDate; DateTime CurrentDate = DateTime.Today; TimeSpan ts = CurrentDate.Subtract(lastloginDate); int Days = Convert.ToInt32(ts.TotalDays); if (Days > 10) { ScriptManager.RegisterClientScriptBlock(LoginUser, GetType(), "a", "alert('Your password has been expired..')", true); } else if (user == null) { LoginUser.FailureText = "User not Found.."; return; } else { string role = string.Empty; if (user.UserTypeId == 1) { role = "Admin"; } else if (user.UserTypeId == 2) { role = "CompanyUser"; } else if (user.UserTypeId == 3) { role = "AgentUser"; } else if (user.UserTypeId == 4) { role = "SuperAdmin"; } FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.FullName, DateTime.Now, DateTime.Now.AddMinutes(30), false, role); string encTicket = FormsAuthentication.Encrypt(ticket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); //HttpCookie MyCookies = new HttpCookie("myCookie"); //MyCookies.Values.Add("userId", user.LoginId.ToString()); //Response.Cookies.Add(MyCookies); //Session["LoginId"] = user.LoginId; //Response.Redirect("Index.aspx"); //FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, LoginUser.RememberMeSet); //UpdateLoginDate(DateTime.Now, user.LoginId); } } else { // added by divaker //if (chkRem.Checked) //{ // Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30); // Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30); //} //else //{ // Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1); // Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1); //} //Response.Cookies["UserName"].Value = UserName.Text.Trim(); //Response.Cookies["Password"].Value = Password.Text.Trim(); string role = string.Empty; if (user.UserTypeId == 1) { role = "Admin"; } else if (user.UserTypeId == 2) { role = "CompanyUser"; } else if (user.UserTypeId == 3) { role = "AgentUser"; } else if (user.UserTypeId == 4) { role = "SuperAdmin"; } // var userRoles = Roles(UserId, SFConfig.ApplicationName, SFConfig.RoleDBConnString); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(user.UserId, user.FullName, DateTime.Now, DateTime.Now.AddMinutes(30), false, role, FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(ticket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); HttpCookie MyCookies = new HttpCookie("myCookie"); MyCookies.Values.Add("userId", user.LoginId.ToString()); Response.Cookies.Add(MyCookies); //FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, LoginUser.RememberMeSet); //UpdateLoginDate(DateTime.Now, user.LoginId); //Session["LoginUser"] = user.FullName; //Session["MobileNo"] = user.MobileNo; //Session["EmailId"] = user.EmailId; Session["LoginId"] = user.UserId; Session["AgentId"] = null; bool adminVal = ValidateUser(); Session["adminValidate"] = adminVal; Response.Redirect("Index.aspx"); } } else if (ValidateAgent()) { Agent agent = new Agent(); UserDom user = new UserDom(); agent = agentBal.ReadAgentById(LoginUser.UserName); string role = string.Empty; role = "AgentUser"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(agent.AgentLocationId, agent.AgentName, DateTime.Now, DateTime.Now.AddMinutes(30), false, role, FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(ticket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); HttpCookie MyCookies = new HttpCookie("myCookie"); MyCookies.Values.Add("userId", agent.AgentName.ToString()); // basePage.LoggedInUser.LoginId = agent.AgentLocationId.ToString(); Session["AgentId"] = agent.AgentId; Response.Cookies.Add(MyCookies); Session["LocationId"] = agent.AgentLocationId; bool agentVal = ValidateAgent(); Session["agentValidate"] = agentVal; Response.Redirect("Index.aspx"); } else { Response.Write("<Script language='javascript'>alert('Your User Id or Password is incorrect. please try again');</script>"); } }