麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 安全知識 > 正文

SharePoint2013 以其他用戶登錄和修改AD域用戶密碼

2024-07-05 04:46:26
字體:
來源:轉載
供稿:網友

  sharepoint默認是沒有修改AD密碼 和切換 用戶的功能,這里我用future的方式來實現。

  部署wsp前:

  部署后:

  點擊以其他用戶身份登錄

  點擊修改用戶密碼:

  這里的擴展才菜單我們用CustomAction來實現,我們需要添加空項目來部署它

  以其他用戶身份登錄得xml如下:

  修改用戶密碼的xml如下:

  這里我們需要新建一個應用程序頁面,首先需要添加路徑映射:

  添加應用程序頁面的代碼如下:

<%@AssemblyName="$SharePoint.PRoject.AssemblyFullName$"%><%@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{//FieldsprivateWindowsImpersonationContextctx=null;//MethodspublicvoidBeginImpersonation(){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();}}//PropertiespublicboolIsImpersonated{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|","");}}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美成人黄色 | 黄色av网站免费 | 免费99热在线观看 | 亚洲欧美一区二区三区在线观看 | 久久久久久久一区 | 天天草天天干天天射 | 请播放一级毛片 | 草草视频在线播放 | 一区二区三区小视频 | 亚洲精久久 | 国产成人免费精品 | 成人一级视频在线观看 | 国产成人自拍小视频 | 亚洲福利在线观看视频 | h视频在线播放 | 国产日韩在线观看一区 | 福利在线播放 | 美女久久久久 | 看av网址 | www噜噜偷拍在线视频 | 黄视频网站免费 | 久久久久国产成人免费精品免费 | 一级做a爰片性色毛片2021 | freexxx69性欧美hd | av手机免费在线观看 | 亚洲一区二区三区视频免费 | 91精品国产乱码久久桃 | 鲁久久| 国产一区二区精彩视频 | 99精品视频一区二区三区 | 日本欧美一区二区三区在线观看 | 亚洲精品v天堂中文字幕 | 日韩视频高清 | 男人的天堂色偷偷 | 久精品久久 | 最新毛片在线观看 | av电影在线免费观看 | 久久精品小短片 | 国产在线精品一区二区不卡 | 九草在线| 大片毛片 |