CKS:FBA - Fix for Change Password link on AD sites

Topics: General/Misc., Internet/Extranet Edition
Apr 21, 2009 at 5:37 PM
The current FBAChangePasswordPage feature uses a custom action to add a Change Password link to the StandardMenu/PersonalActions section.  Only problem is, this link appears both on the AD and Forms Based Auth sites, when it only makes sense on the FBA site.

The following change will fix this:

Elements file:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="11CEFAA1-F69B-40c3-850C-F229CB3B2561}"
    GroupId="PersonalActions"
    Location="Microsoft.SharePoint.StandardMenu"
    Title="Change Password"
    ControlAssembly="CKS.FormsBasedAuthentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d0c9b215512a2c5d"
    ControlClass="CKS.FormsBasedAuthentication.ChangePasswordLink"
  />
</Elements>

New code class, ChangePasswordLink.cs:

using System;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CKS.FormsBasedAuthentication
{
public class ChangePasswordLink : WebControl
{
/// <summary>
/// Handles the <see cref="E:System.Web.UI.Control.Load"/> event.
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
base.OnLoad(e);
}

/// <summary>
/// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
/// </summary>
protected override void CreateChildControls()
{
if (this.ChildControlsCreated)
return;

//bail if not using Forms Authentication
if (SPSecurity.AuthenticationMode != System.Web.Configuration.AuthenticationMode.Forms)
return;

base.CreateChildControls();

//Create the Change Password link
MenuItemTemplate changePasswordMenuItem = new MenuItemTemplate("Change Password");
changePasswordMenuItem.Description = "Change your current password.";
changePasswordMenuItem.ClientOnClickNavigateUrl = "/_layouts/fba/ChangePassword.aspx";
changePasswordMenuItem.Sequence = 1;
Controls.Add(changePasswordMenuItem);
}
}
}