SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍
sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现。
部署wsp前:
部署后:
点击以其他用户身份登录
点击修改用户密码:
这里的扩展才菜单我们用CustomAction来实现,我们需要添加空项目来部署它
以其他用户身份登录得xml如下:
修改用户密码的xml如下:
这里我们需要新建一个应用程序页面,首先需要添加路径映射:
添加应用程序页面的代码如下:
修改密码
域 | : | |
旧密码 | : | |
新密码 | : | |
确认新密码 | : | |
|
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using System.Security.Principal;using System.DirectoryServices.AccountManagement;namespace SharePointProjectDemo.Layouts.ChangePassword{ public class Impersonator { // Fields private WindowsImpersonationContext ctx = null; // Methods public void BeginImpersonation() { try { if (!WindowsIdentity.GetCurrent().IsSystem) { this.ctx = WindowsIdentity.Impersonate(WindowsIdentity.GetCurrent().Token); this.IsImpersonated = true; } } catch { this.IsImpersonated = false; } } public void StopImpersonation() { if (this.ctx != null) { this.ctx.Undo(); } } // Properties public bool IsImpersonated { set; get; } } public partial class ChangePassword : LayoutsPageBase { protected void btnChangePwd_Click(object sender, EventArgs e) { string str = this.txtPass1.Text.Trim(); string str2 = this.txtPass2.Text.Trim(); string str3 = this.txtOld.Text.Trim(); string str4 = this.txtdomain.Text.Trim(); if (string.IsNullOrWhiteSpace(str4)) { this.ltMsg.Text = "域不能为空!"; } else if (string.IsNullOrWhiteSpace(str3)) { this.ltMsg.Text = "旧密码不能为空!"; } else if (string.IsNullOrWhiteSpace(str)) { this.ltMsg.Text = "新密码不能为空!"; } else if (str == str2) { this.ChangeUserPassword(this.txtPass2.Text.Trim(), str3, str4); } else { this.ltMsg.Text = "两次新密码不一致,请检查!"; } } private void ChangeUserPassword(string NewPwd, string OldPwd, string domain) { try { Impersonator impersonator = new Impersonator(); impersonator.BeginImpersonation(); using (PrincipalContext context = this.GetPContext(OldPwd, domain)) { using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, GetLoginName())) { principal.ChangePassword(OldPwd, NewPwd); } } if (impersonator.IsImpersonated) { impersonator.StopImpersonation(); this.ltMsg.Text = "已成功修改密码!"; } else { this.ltMsg.Text = "无法修改您的密码,请联系您的系统管理员!"; } } catch (Exception exception) { this.ltMsg.Text = exception.Message; } } private string GetDomainContainter(string domain) { string str = string.Empty; string[] strArray = domain.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); foreach (string str2 in strArray) { str = str + "DC=" + str2 + ","; } if (str.Length > 0) { str = str.Substring(0, str.Length - 1); } return str; } private string GetLoginName() { string username= SPContext.Current.Web.CurrentUser.LoginName.Replace("i:0#.w|", ""); if(username.EndsWith(@"\system")) { username = username.Replace("system", "sherry"); } return username; } private string GetLoginNameDomain() { string[] strArray = GetLoginName().Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length == 2) { return strArray[0]; } return null; } private PrincipalContext GetPContext(string OldPwd, string domain) { return new PrincipalContext(ContextType.Domain, domain, this.GetDomainContainter(domain), ContextOptions.Negotiate, this.GetLoginName(), OldPwd); } protected void Page_Load(object sender, EventArgs e) { this.ltMsg.Text = GetLoginName().Replace("i:0#.w|", ""); } }}
推荐系统
雨林木风 winxp下载 纯净版 永久激活 winxp ghost系统 sp3 系统下载
系统大小:0MB系统类型:WinXP雨林木风在系统方面技术积累雄厚深耕多年,打造了国内重装系统行业知名品牌,雨林木风WindowsXP其系统口碑得到许多人认可,积累了广大的用户群体,是一款稳定流畅的系统,雨林木风 winxp下载 纯净版 永久激活 winxp ghost系统 sp3 系统下载,有需要的朋友速度下载吧。
系统等级:进入下载 >萝卜家园win7纯净版 ghost系统下载 x64 联想电脑专用
系统大小:0MB系统类型:Win7萝卜家园win7纯净版是款非常纯净的win7系统,此版本优化更新了大量的驱动,帮助用户们进行舒适的使用,更加的适合家庭办公的使用,方便用户,有需要的用户们快来下载安装吧。
系统等级:进入下载 >雨林木风xp系统 xp系统纯净版 winXP ghost xp sp3 纯净版系统下载
系统大小:1.01GB系统类型:WinXP雨林木风xp系统 xp系统纯净版 winXP ghost xp sp3 纯净版系统下载,雨林木风WinXP系统技术积累雄厚深耕多年,采用了新的系统功能和硬件驱动,可以更好的发挥系统的性能,优化了系统、驱动对硬件的加速,加固了系统安全策略,运行环境安全可靠稳定。
系统等级:进入下载 >萝卜家园win10企业版 免激活密钥 激活工具 V2023 X64位系统下载
系统大小:0MB系统类型:Win10萝卜家园在系统方面技术积累雄厚深耕多年,打造了国内重装系统行业的萝卜家园品牌,(win10企业版,win10 ghost,win10镜像),萝卜家园win10企业版 免激活密钥 激活工具 ghost镜像 X64位系统下载,其系统口碑得到许多人认可,积累了广大的用户群体,萝卜家园win10纯净版是一款稳定流畅的系统,一直以来都以用户为中心,是由萝卜家园win10团队推出的萝卜家园
系统等级:进入下载 >萝卜家园windows10游戏版 win10游戏专业版 V2023 X64位系统下载
系统大小:0MB系统类型:Win10萝卜家园windows10游戏版 win10游戏专业版 ghost X64位 系统下载,萝卜家园在系统方面技术积累雄厚深耕多年,打造了国内重装系统行业的萝卜家园品牌,其系统口碑得到许多人认可,积累了广大的用户群体,萝卜家园win10纯净版是一款稳定流畅的系统,一直以来都以用户为中心,是由萝卜家园win10团队推出的萝卜家园win10国内镜像版,基于国内用户的习惯,做
系统等级:进入下载 >windows11下载 萝卜家园win11专业版 X64位 V2023官网下载
系统大小:0MB系统类型:Win11萝卜家园在系统方面技术积累雄厚深耕多年,windows11下载 萝卜家园win11专业版 X64位 官网正式版可以更好的发挥系统的性能,优化了系统、驱动对硬件的加速,使得软件在WINDOWS11系统中运行得更加流畅,加固了系统安全策略,WINDOWS11系统在家用办公上跑分表现都是非常优秀,完美的兼容各种硬件和软件,运行环境安全可靠稳定。
系统等级:进入下载 >
热门系统
推荐软件
推荐应用
推荐游戏
热门文章
常用系统
- 1windows10专业版下载 系统之家x64位系统 免激活工具 GHOST镜像下载
- 2Windows11稳定版 番茄花园win11正式版 ghost系统 ISO镜像 X64位 下载
- 3电脑公司windows7稳定版 ghost x64位 v2023 官网镜像下载
- 4技术员联盟Windows7 64位技术专业版 永久激活 官网镜像下载
- 5windows10娱乐版下载 技术员联盟64位系统 官网镜像下载 华硕电脑专用
- 6Wi7系统下载 64位高速旗舰版 技术员联盟windows 免激活工具
- 7技术员联盟win7纯净版系统下载 64位 ghost ISO 镜像V2023
- 8番茄花园winXP系统下载 windows xp ghost v2022.05 sp3 系统下载
- 9win10大师版下载 萝卜家园64位专业版 官网镜像下载 笔记本专用