Example #1
0
        void btnResetPwd_Click(object sender, EventArgs e)
        {
            try
            {
                this._domainName       = ConfigurationManager.AppSettings["mmsDomainName"].ToString();
                this._adminOfDC        = ConfigurationManager.AppSettings["mmsAdminOfDC"].ToString();
                this._pwdOfDC          = ConfigurationManager.AppSettings["mmsPwdOfDC"].ToString();
                this._nameOfRootOU     = ConfigurationManager.AppSettings["mmsNameOfRootOU"].ToString();
                this._domainAbbreviate = ConfigurationManager.AppSettings["mmsDomainAbbreviate"].ToString();

                using (DirectoryContext dc = new DirectoryContext(this._domainName, this._adminOfDC, this._pwdOfDC))
                {
                    this.users = dc.Users;
                    DirectoryUser curUser = users.SingleOrDefault(u => (this._domainAbbreviate + "\\" + u.LogonName).ToLower() == SPContext.Current.Web.CurrentUser.LoginName.ToLower());
                    curUser.ChangePassword(this.txtOldPwd.Text.Trim(), this.txtNewPwd.Text.Trim());
                    dc.SubmitChanges();
                }
                ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('修改密码成功!')</script>");
            }
            catch (Exception ex)
            {
                System.Reflection.MethodBase mb = System.Reflection.MethodBase.GetCurrentMethod();
                LogToDBHelper lhelper           = LogToDBHelper.Instance;
                lhelper.WriteLog(ex.Message, "错误", string.Format("{0}.{1}", mb.ReflectedType.Name, mb.Name));
                ClientScript.RegisterClientScriptBlock(typeof(string), "提示", string.Format("<script>alert('{0}')</script>", LogToDBHelper.LOG_MSG_LOADERROR));
            }
        }