讓使用者在 WSSv3(MOSS 2007) 變更密碼

Sharepoint 的使用者資訊設定裡, 並沒有提供讓使用者自行修改密碼的功能。還好 WSSv3 (MOSS 2007) 使用的是 ASP.NET 2.0 Membership Provider, 修改密碼的工作可以交給 Membership Provider 來處理, 我們只要使用 <asp:ChangePassword /> 這個控制項, 就可以提供變更密碼的功能。

一種方法是把 <asp:ChangePassword /> 做成 WebPart (或者是加到 SmartPart 之中), 然後建立一個網頁組件頁面, 再把 WebPart 放進頁面中。

另一種作法, 是建立一個專屬的 .aspx 頁面到 layouts 目錄, 因為變更使用者個人資訊的頁面也是這樣。將下面的檔案存到 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\userchgpwd.aspx, (如果你的 layouts 位置不同請找一下正確的路徑)

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" %>
<script runat="server">
protected void cp1_ContinueButtonClick(object sender, EventArgs e)
{
    Response.Redirect(Request.ApplicationPath);
}
</script>

<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
    變更密碼
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server" OnContinueButtonClick="cp1_ContinueButtonClick">
    <table cellspacing="0" cellpadding="0">
        <tr>
        <td>
            <asp:ChangePassword id="cp1" runat="server">
            </asp:ChangePassword>
         </td>
         </tr>
     </table>
</asp:Content> 

 第二步則是在使用者選單裡加入變更密碼的連結, 要修改 C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx 這個檔案, 在 ID_PersonalInformation 與 ID_LoginAsDifferentUser 之間加入一個新的 <SharePoint:MenuItemTemplate />, 並把點選路徑指向 /_layouts/userchgpwd.aspx (如果你的密碼變更路徑不一樣, 要改成正確的路徑), 就會在使用者選單裡多一個變更密碼的選項。

<SharePoint:MenuItemTemplate runat="server" id="ID_PersonalInformation"
    ...
     />

<SharePoint:MenuItemTemplate runat="server" id="ID_ChangePassword"
    Text="變更密碼"
    Description="修改個人登入密碼"
    MenuGroupId="100"
    Sequence="100"
    UseShortId="true"
    ClientOnClickNavigateUrl="/_layouts/userchgpwd.aspx"
    />

<SharePoint:MenuItemTemplate runat="server" id="ID_LoginAsDifferentUser"
    ...
    />

Comments

  • Anonymous
    May 08, 2007
    您好,我有參照你的作法去試 但因為我們是用AD的帳號登入到網站 所以在更密碼時,他會顯示有不知名的錯誤 小弟不知道是不是AD的問題 若大哥知道,可否教一下我呢,謝謝。

  • Anonymous
    May 09, 2007
    "不知名的錯誤" 是表示程式發生未處理的 Exception, SharePoint 不會像 ASP.NET 預設方式直接將 Exception 輸出到畫面上, 必須自行用 try...catch... 攔下 Exception, 才能 debug

  • Anonymous
    May 26, 2007
    您好,我也参照你的方法,和上面那位大哥一样也是显示为:“未知错误”,不知是不是因为服务器是采用AD验证造成的,如果方便的话能不能详细告知解决方法,谢谢了!我的邮箱:c_Zs@163.com

  • Anonymous
    June 19, 2007
    The comment has been removed

  • Anonymous
    August 13, 2007
    Sharepoint的使用者资讯设定裡,并没有提供让使用者自行修改密码的功能。还好WSSv3(MOSS2007)使用的是ASP.NET2.0MembershipProvider,...

  • Anonymous
    March 30, 2008
    The comment has been removed

  • Anonymous
    May 18, 2008
    我的AD整合,也是出現未知的錯誤,如有解決能否分享一下哦…… 我的Mail:weiranth@google.com

  • Anonymous
    August 09, 2009
    我的也是AD整合,moss与AD分开安装的.修改密码提示未知错误.希望帮助一下