protected void btnLogin_Click(object sender, EventArgs e) { try { if (txtUserName.Text.Trim() != "" && txtPassword.Text != "") { objDataSet = MasterCode.RetrieveQuery("select User_Id,Isactive,Username,UserCode,UserRights,Staff_Id from tbl_user where Username='******' and Password='******'"); if (objDataSet.Tables[0].Rows.Count > 0) { string IsActive = (objDataSet.Tables[0].Rows[0][1].ToString()); string UserIP = Request.UserHostAddress; if (IsActive == "True") { DataSet objDataSet1 = null; if (objDataSet.Tables[0].Rows[0]["Username"].ToString() != "admin") { objDataSet1 = MasterCode.RetrieveQuery("Select Name from tbl_Register_User where Register_Id=" + objDataSet.Tables[0].Rows[0]["Staff_Id"].ToString()); Session["Name"] = objDataSet1.Tables[0].Rows[0]["Name"].ToString(); } else { Session["Name"] = "admin"; } Session["UserId"] = Convert.ToInt32(objDataSet.Tables[0].Rows[0]["User_Id"].ToString()); Session["UserCode"] = objDataSet.Tables[0].Rows[0]["Usercode"].ToString(); Session["UserName"] = objDataSet.Tables[0].Rows[0]["Username"].ToString(); objMaster.UserName = txtUserName.Text.Trim(); objMaster.Password = txtPassword.Text.Trim(); objMaster.IPAddress = UserIP; objMaster.DateTime = DateTime.Now.AddHours(Connection.SetHours); objMaster.UserId = Convert.ToInt32(Session["UserId"].ToString()); DataSet objDataSetLoginId = MasterCode.InsertLoginDetails(objMaster); if (objDataSetLoginId.Tables[0].Rows.Count > 0) { Session["LoginId"] = objDataSetLoginId.Tables[0].Rows[0][0].ToString(); } DataTable menuData = new DataTable(); menuData = GetMenuData(objDataSet.Tables[0].Rows[0]["UserRights"].ToString()); AddTopMenuItems(menuData); Session["Menu"] = menu.Replace("<ul></ul>", ""); //if (objDataSet.Tables[0].Rows[0]["User_Id"].ToString() == "1" || objDataSet.Tables[0].Rows[0]["User_Id"].ToString() == "2" || objDataSet.Tables[0].Rows[0]["User_Id"].ToString() == "3") if (Session["RedirectURL"] == null) { Response.Redirect("Admin/frmHome.aspx", false); } else { Response.Redirect(Session["RedirectURL"].ToString(), false); Session["RedirectURL"] = null; } //else // Response.Redirect("User/UserHome.aspx", false); } else { ShowNotification("Login", "Please Contact Administrator..!", NotificationType.error); } } else { DateTime Date = DateTime.Today; objMaster.UserName = txtUserName.Text.Trim(); objMaster.Password = txtPassword.Text.Trim(); objMaster.IPAddress = Request.UserHostAddress; objMaster.DateTime = Date; MasterCode.InsertFail(objMaster); objDataSet = objMaster.GetCount(txtUserName.Text.Trim(), Request.UserHostAddress, Date); if (objDataSet.Tables[0].Rows.Count >= 3) { objMaster.IsActive = "False"; objMaster.UserName = txtUserName.Text.Trim(); Session["count"] = 0; int b = objMaster.Block(); if (b != 0) { ShowNotification("Login", "Your Login is Blocked", NotificationType.error); Session["UserId"] = "0"; } } else { ShowNotification("Login", "Invalid Login!", NotificationType.error); Session["UserId"] = "0"; } } } else { ShowNotification("Login", "Please Enter All Fields!", NotificationType.error); } } catch (Exception Ex) { StackTrace objStackTrace = new StackTrace(); string calledMethodName = objStackTrace.GetFrame(1).GetMethod().Name; string dispErrorMsg = string.Format("Error occurred in {0} method.", calledMethodName); LogFile.WriteToLog(dispErrorMsg, Ex); SendLogFile.SendMail(); ShowNotification("Login", "Database is not Connected Properly..!", NotificationType.error); } }