If you are thinking about globally changing the behavior of SharePoint People Picker with custom validation logic, without going through the hassle of modifying every single page in SharePoint, then you are in the right place.
SharePoint application pages and user controls with a people picker declaratively uses the Microsoft.SharePoint.WebControls.PeopleEditor Web Control and sets the control’s properties to change its validation logic that meets specific requirements.
If you want to display only users that are members of a site collection or to customize the search filter for active directory, you might want to use STSADM to set people picker settings in a higher scope than setting the properties of an instance.
However, STSADM will not completely meet your needs, as you might have some random reason to have a custom logic:
-
You might want to restrict users or certain members of some special domain group from getting resolved.
-
You might want to make sure that the resolved users are in fact active (not disabled) accounts in active directory;
-
You might even want to resolve users from a data source that the people picker cannot reach OOTB.
I knew in my head that there was an elegant way to customize the validation logic of the SharePoint people picker and have the changes propagate across a SharePoint Web Application. So, I kept asking my best friend Google, “globally replace a Web control using the Web.Config”, “and please answer my prayers” (I'm telling you, I couldn’t find a clue; maybe I should try Microsoft Bing). And, then boom! I remembered that Jonas Nilsson, one of my favorite mentors from Bamboo Solutions mentioned changing something in the Web.Config to redirect the declarative usage of a control to a new control. Yes! A couple phone conversations later, I found out it was just two words, “Tag Mapping” (stupid me! I couldn’t even remember that?).
For whatever reason, if you need to implement custom validation logic and have the effect be global, overriding the PeopleEditor SharePoint control accordingly, and using Tag Mapping to redirect all declarative usage of the SharePoint People Picker control is inevitable. Tag Mapping (a new feature in ASP.NET 2.0) defines a collection of tag types to be remapped to other tag types at compile time. According to Nickil Kothari’s blog, it was originally invented as part of the Web Part framework so as to allow the ASP.NET WebPartManager to be mapped to the derived SharePoint WebPartManager implementation without having to change individual pages.
Long story short, you should just need to do the following:
using SharePointControls = Microsoft.SharePoint.WebControls;
namespace NaT.SharePoint.WebControls
{
public class PeopleEditor : SharePointControls.PeopleEditor
{
public override SharePointControls.PickerEntity ValidateEntity(SharePointControls.PickerEntity entity)
{
SharePointControls.PickerEntity validatedEntity = base.ValidateEntity(entity);
if (validatedEntity.IsResolved == true)
{
bool isGoodToGo = true;
//HERE, you can validate whether you want the entity to be resolved or not:
// - Check if user has a MOSS profile
// - Check if user is NOT disabled
// - User is not a denied user from the web application policy, etc, and set isGoodToGo accordingly
if (isGoodToGo == false)
{
validatedEntity.IsResolved = false;
}
}
return validatedEntity;
}
}
}
- 3. Sign your assembly with a Strong Name
- 4. Install assembly into the GAC
- 5. Put tag mapping entry in the Web.Config
1: <configuration>
2: <system.web>
3: <pages>
4: <tagMapping>
5: <add tagType="Microsoft.SharePoint.WebControls.PeopleEditor"
6: mappedTagType="NaT.SharePoint.WebControls.PeopleEditor"/>
7: </tagMapping>
8: </pages>
9: </system.web>
10: </configuration>
To Tag-Mapping,
NaT
Posted
Jun 20 2009, 04:16 AM
by
Natnael K. Gebremariam