a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 應用 > 系統工具 > 正文

SharePoint2013 以其他用戶登錄和修改AD域用戶密碼的功能使用介紹

2020-07-10 20:36:02
字體:
來源:轉載
供稿:網友

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

部署wsp前:

部署后:

點擊以其他用戶身份登錄

點擊修改用戶密碼:

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

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

修改用戶密碼的xml如下:

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

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


<%@ Assembly Name="$SharePoint.Project.AssemblyFullName___FCKpd___0quot; %><%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %><%@ Import Namespace="Microsoft.SharePoint" %><%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChangePassword.aspx.cs" Inherits="SharePointProjectDemo.Layouts.ChangePassword.ChangePassword" DynamicMasterPageFile="~masterurl/default.master" %><asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"></asp:Content><asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">     <asp:Literal ID="ltMsg" EnableViewState="false" runat="server"></asp:Literal><div>    <h3>        <span>修改密碼</span>    </h3>    <table width="400px">         <tr>            <td>               域            </td>            <td>                :            </td>            <td>                <asp:TextBox ID="txtdomain" runat="server" ></asp:TextBox>            </td>        </tr>         <tr>            <td>                舊密碼            </td>            <td>                :            </td>            <td>                <asp:TextBox ID="txtOld" runat="server" TextMode="Password"></asp:TextBox>            </td>        </tr>        <tr>            <td>                新密碼            </td>            <td>                :            </td>            <td>                <asp:TextBox ID="txtPass1" runat="server" TextMode="Password"></asp:TextBox>            </td>        </tr>        <tr>            <td>                確認新密碼            </td>            <td>                :            </td>            <td>                <asp:TextBox ID="txtPass2" runat="server" TextMode="Password"></asp:TextBox>            </td>        </tr>        <tr>            <td colspan="3" align="center">                <br />                <asp:Button ID="btnChangePwd" runat="server" Text="修改密碼" OnClick="btnChangePwd_Click" />            </td>        </tr>    </table>    <br />    <br /></div></asp:Content><asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">修改密碼</asp:Content><asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >修改密碼</asp:Content>



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|", "");        }    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 特级淫片女子高清视频在线观看 | 国产精品99999 | 成年人黄色免费视频 | 高清国产视频 | 毛片福利| 亚洲第一av | 再深点灬舒服灬太大了添少妇视频 | 欧美日韩视频一区二区 | 国产精品久久久久久亚洲调教 | 精品九九九 | 亚洲精品v | 在线日韩| 2018国产大陆天天弄 | 久久综合精品视频 | 久久久中文字幕 | 国产精品久久久久久久久 | 亚洲xxxx在线观看 | 久久久国产一区二区三区四区小说 | 日韩中文字幕在线播放 | 亚洲国产精品一区 | 日韩视频精品 | 日韩在线免费 | 电影一区二区在线 | 欧美午夜在线 | 激情com| 成人网电影 | 中文字幕免费看 | 宅宅久久 | 99国产精品99久久久久久 | 91久久久久久久久 | 日韩理论视频 | 久久99精品国产麻豆婷婷洗澡 | 91麻豆精品国产91久久久久久 | 国产精品无码永久免费888 | 精品乱码一区二区 | 在线日韩欧美 | 亚洲蜜臀av乱码久久精品蜜桃 | 在线观看第一页 | 激情视频网 | 久久久激情| 操碰97|