protected void CmdLogin_Click(object sender, EventArgs e) { _path = "LDAP://#"; //lblerrormsg.Text = string.Empty; try { if (!IsAuthenticated(Convert.ToString(ConfigurationManager.AppSettings["domain"]), Login1.UserName, Login1.Password)) { return; } SqlCommand cmd = new SqlCommand("#"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@UserID", SqlDbType.NVarChar, 50).Value = Login1.UserName; LMS dal = new LMS(); DataSet ds = dal.DisconectedMethod(cmd); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { Session["Authorization"] = Convert.ToString(ds.Tables[0].Rows[0]["ROLE"]); Session["UserID"] = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]); Session["EMPLOYEE_NAME"] = Convert.ToString(ds.Tables[0].Rows[0]["EMPLOYEE_NAME"]); Response.Redirect("index.aspx"); } } catch (Exception ex) { Login1.FailureText = ex.Message; } } private bool IsAuthenticated(string domain, string username, string pwd) { string domainAndUsername = domain + @"\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); try { //Bind to the native AdsObject to force authentication. object obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + username + ")"; search.PropertiesToLoad.Add("cn"); SearchResult result = search.FindOne(); if (null == result) { return false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = (string)result.Properties["cn"][0]; } catch (Exception ex) { Login1.FailureText = ex.Message; } return true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)