protected void BtnLogin_Click(object sender, EventArgs e) { try { string domainName = DDL_Domain.SelectedValue; string userName = GetUsername(TxtUserName.Value); IntPtr token = IntPtr.Zero; bool bLogonUser; objControllerLogin = new ControllerLogin(); DataTable dtAcccess = objControllerLogin.GetAccess(domainName, userName); if (dtAcccess.Rows.Count > 0) { bLogonUser = true; } else { bLogonUser = LogonUser(userName, domainName, TxtPassword.Value.ToString(), 2, 0, ref token); } bool bGetUserDetail = Get_User_Detail(userName); // bool bLogonUser = LogonUser(userName, domainName, TxtPassword.Value, 2, 0, ref token); if (bLogonUser) { HttpContext.Current.Session["UserName"] = userName; HttpContext.Current.Session["DomainName"] = domainName; if (bGetUserDetail) { if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) { Response.Cookies["userid"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["pwd"].Expires = DateTime.Now.AddDays(-1); FormsAuthentication.RedirectFromLoginPage(TxtUserName.Value, false); InsertLoginLog(); Response.Redirect("DashboardNew.aspx"); } else { FormsAuthentication.SetAuthCookie(TxtUserName.Value, false); Response.Redirect("Login.aspx"); } } else { ShowDivAlert("You dont have Access. Contact to Administrator"); } } else { ShowDivAlert("Invalid username or password."); } } catch (Exception Ex) { ShowDivAlert("Invalid username or password."); } }