手机
当前位置:查字典教程网 >软件教程 >系统工具 >SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍
SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍
摘要:sharepoint默认是没有修改AD密码和切换用户的功能,这里我用future的方式来实现。部署wsp前:部署后:点击以其他用户身份登录点...

sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现。

部署wsp前:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍1

部署后:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍2

点击以其他用户身份登录

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍3

点击修改用户密码:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍4

这里的扩展才菜单我们用CustomAction来实现,我们需要添加空项目来部署它

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍5

以其他用户身份登录得xml如下:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍6

修改用户密码的xml如下:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍7

这里我们需要新建一个应用程序页面,首先需要添加路径映射:

SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍8

添加应用程序页面的代码如下:

<%@AssemblyName="$SharePoint.Project.AssemblyFullName___FCKpd___0quot;%><%@ImportNamespace="Microsoft.SharePoint.ApplicationPages"%><%@RegisterTagprefix="SharePoint"Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"%><%@RegisterTagprefix="Utilities"Namespace="Microsoft.SharePoint.Utilities"Assembly="Microsoft.SharePoint,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"%><%@RegisterTagprefix="asp"Namespace="System.Web.UI"Assembly="System.Web.Extensions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"%><%@ImportNamespace="Microsoft.SharePoint"%><%@AssemblyName="Microsoft.Web.CommandUI,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"%><%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="ChangePassword.aspx.cs"Inherits="SharePointProjectDemo.Layouts.ChangePassword.ChangePassword"DynamicMasterPageFile="~masterurl/default.master"%><asp:ContentID="PageHead"ContentPlaceHolderID="PlaceHolderAdditionalPageHead"runat="server"></asp:Content><asp:ContentID="Main"ContentPlaceHolderID="PlaceHolderMain"runat="server"> <asp:LiteralID="ltMsg"EnableViewState="false"runat="server"></asp:Literal><div> <h3> <span>修改密码</span> </h3> <tablewidth="400px"> <tr> <td> 域</td> <td> :</td> <td> <asp:TextBoxID="txtdomain"runat="server"></asp:TextBox> </td> </tr> <tr> <td> 旧密码</td> <td> :</td> <td> <asp:TextBoxID="txtOld"runat="server"TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> 新密码</td> <td> :</td> <td> <asp:TextBoxID="txtPass1"runat="server"TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> 确认新密码</td> <td> :</td> <td> <asp:TextBoxID="txtPass2"runat="server"TextMode="Password"></asp:TextBox> </td> </tr> <tr> <tdcolspan="3"align="center"> <br/> <asp:ButtonID="btnChangePwd"runat="server"Text="修改密码"OnClick="btnChangePwd_Click"/> </td> </tr> </table> <br/> <br/></div></asp:Content><asp:ContentID="PageTitle"ContentPlaceHolderID="PlaceHolderPageTitle"runat="server">修改密码</asp:Content><asp:ContentID="PageTitleInTitleArea"ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"runat="server">修改密码</asp:Content>

usingSystem;usingMicrosoft.SharePoint;usingMicrosoft.SharePoint.WebControls;usingSystem.Security.Principal;usingSystem.DirectoryServices.AccountManagement;namespaceSharePointProjectDemo.Layouts.ChangePassword {publicclassImpersonator {//Fields privateWindowsImpersonationContextctx=null;//Methods publicvoidBeginImpersonation() {try {if(!WindowsIdentity.GetCurrent().IsSystem) {this.ctx=WindowsIdentity.Impersonate(WindowsIdentity.GetCurrent().Token);this.IsImpersonated=true; } }catch {this.IsImpersonated=false; } }publicvoidStopImpersonation() {if(this.ctx!=null) {this.ctx.Undo(); } }//Properties publicboolIsImpersonated {set;get; } }publicpartialclassChangePassword:LayoutsPageBase {protectedvoidbtnChangePwd_Click(objectsender,EventArgse) {stringstr=this.txtPass1.Text.Trim();stringstr2=this.txtPass2.Text.Trim();stringstr3=this.txtOld.Text.Trim();stringstr4=this.txtdomain.Text.Trim();if(string.IsNullOrWhiteSpace(str4)) {this.ltMsg.Text="域不能为空!"; }elseif(string.IsNullOrWhiteSpace(str3)) {this.ltMsg.Text="旧密码不能为空!"; }elseif(string.IsNullOrWhiteSpace(str)) {this.ltMsg.Text="新密码不能为空!"; }elseif(str==str2) {this.ChangeUserPassword(this.txtPass2.Text.Trim(),str3,str4); }else {this.ltMsg.Text="两次新密码不一致,请检查!"; } }privatevoidChangeUserPassword(stringNewPwd,stringOldPwd,stringdomain) {try { Impersonatorimpersonator=newImpersonator(); impersonator.BeginImpersonation();using(PrincipalContextcontext=this.GetPContext(OldPwd,domain)) {using(UserPrincipalprincipal=UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName,GetLoginName())) { principal.ChangePassword(OldPwd,NewPwd); } }if(impersonator.IsImpersonated) { impersonator.StopImpersonation();this.ltMsg.Text="已成功修改密码!"; }else {this.ltMsg.Text="无法修改您的密码,请联系您的系统管理员!"; } }catch(Exceptionexception) {this.ltMsg.Text=exception.Message; } }privatestringGetDomainContainter(stringdomain) {stringstr=string.Empty;string[]strArray=domain.Split(newchar[]{'.'},StringSplitOptions.RemoveEmptyEntries);foreach(stringstr2instrArray) { str=str+"DC="+str2+","; }if(str.Length>0) { str=str.Substring(0,str.Length-1); }returnstr; }privatestringGetLoginName() {stringusername=SPContext.Current.Web.CurrentUser.LoginName.Replace("i:0#.w|","");if(username.EndsWith(@"system")) { username=username.Replace("system","sherry"); }returnusername; }privatestringGetLoginNameDomain() {string[]strArray=GetLoginName().Split(newchar[]{''},StringSplitOptions.RemoveEmptyEntries);if(strArray.Length==2) {returnstrArray[0]; }returnnull; }privatePrincipalContextGetPContext(stringOldPwd,stringdomain) {returnnewPrincipalContext(ContextType.Domain,domain,this.GetDomainContainter(domain),ContextOptions.Negotiate,this.GetLoginName(),OldPwd); }protectedvoidPage_Load(objectsender,EventArgse) {this.ltMsg.Text=GetLoginName().Replace("i:0#.w|",""); } } }

【SharePoint2013 以其他用户登录和修改AD域用户密码的功能使用介绍】相关文章:

DEP驱动备份工具怎么用?U极速DEP驱动备份功能使用教程

驱动人生怎么获得修电脑免费服务码?驱动人生修电脑教程

Win10手机版回滚WP8.1刷机工具更新到v3.1.2:支持LG Lancet

腾讯电脑管家账号包找回的好处及功能介绍

腾讯电脑管家的清理插件功能使用介绍(问答式)

腾讯电脑管家的沙箱功能详细介绍

VMware 增强工具安装与作用介绍[图文]

KK按键找颜色点功能使用方法介绍

startuprun (strun启动项管理工具) 1.22 中文版使用介绍

无极重装系统的安装使用图文教程

精品推荐
分类导航