protected void Unnamed1_Authenticate(object sender, AuthenticateEventArgs e) { bool valid = false; using (var context = new PrincipalContext(ContextType.Domain)) { var login = sender as System.Web.UI.WebControls.Login; if (login != null) { valid = context.ValidateCredentials(login.UserName, login.Password); if (valid) { var dal = new UsersDal(); var loginWithDomain = AuthProvider.LoginWithDomain(login.UserName); if (!dal.IsUserExists(AuthProvider.LoginWithDomain(login.UserName))) { Session["CurrentUserId"] = dal.RegisterNewUser(loginWithDomain, AuthProvider.GetUserFullNameByDomainIdentity(login.UserName)); Login1.DestinationPageUrl = "Profile.aspx"; //e.Authenticated = false; //return; } else { Session["CurrentUserId"] = (new UsersDal()).GetUserGUIDByLogin(loginWithDomain); } Session["CurrentUser"] = loginWithDomain; dal.UsersStatisticsUpdateLoginCount(AuthProvider.UserKey(Session)); } } } e.Authenticated = valid; }
protected void BtnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TbUserLogin.Text)) { var dal = new UsersDal(); if (!dal.IsUserExists(TbUserLogin.Text)) { dal.RegisterNewUser(AuthProvider.LoginWithDomain(TbUserLogin.Text), AuthProvider.GetUserFullNameByDomainIdentity(TbUserLogin.Text)); TbUserLogin.Text = string.Empty; lblUserName.Text = string.Empty; LblDepartment.Text = string.Empty; LblEmail.Text = string.Empty; LblOffice.Text = string.Empty; ReloadData(); } } }