A little note to self about custom Membership and Role Providers and SharePoint 2010 Claims
Claims, Development, Note to self, SharePoint 2010Table of Contents
- Creating custom Membership and Role Providers
- Registering custom Membership and Role Providers with SharePoint 2010 Claims
- Resources
Creating custom Membership and Role Providers
You can create a custom Membership provider by inheriting from the System.Web.Security.MembershipProvider class. For a custom Role Provider you need to inherit from the System.Web.Security.RoleProvider class.
A custom Membership Provider has to implement at least the following methods in order to work with SharePoint 2010:
- FindUsersByEmail
- FindUsersByName
- GetUser(string, bool)
- GetUser(object, bool)
- GetUserNameByEmail
- ValidateUser
A custom Role Provider has to implement at least the following methods in order to work with SharePoint 2010:
- GetRolesForUser
- RoleExists
Deploy the assembly to GAC as it’s being used outside the context of the Web Application.
In case you need to debug the Membership and/or Role provider you need to attach the debugger to the w3wp process associated with the SecurityTokenServiceApplicationPool application pool (use appcmd.exe list wp to find out which one it is).
The STSAppPool can be refreshed by resetting it through IIS Manager or resetting IIS.
All login errors are being logged to the ULS log so it’s worth to have a look in there in case of trouble.
Registering custom Membership and Role Providers with SharePoint 2010 Claims
- Create a custom Web Application that uses Claims Authentication
- Select FBA and provide names for the Membership and Role Providers
- Register both providers with your Web Application (web.config)
- system.web/membership/providers/add
- system.web/roleManager/providers/add
- Register both providers with Central Administration (web.config). You have to add the whole roleManager and membership sections here.
- Register both providers with the Security Token Service (web.config located in 14\WebService\SecurityToken. Add the following code snippet:
<system.web> <roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false"> <providers> <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <add name="MyRoleProvider" type="MyRoleProvider, MyAuth, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000"/> </providers> </roleManager> <membership defaultProvider="i"> <providers> <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <add name="MyMembershipProvider" type="MyMembershipProvider, MyAuth, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000"/> </providers> </membership> </system.web>
Resources
- Forms Authentication in SharePoint Products and Technologies (Part 2): Membership and Role Provider Samples (watch out for the HttpContext.Current as it’s NULL when using with SP2010 Claims)
- Configure Forms Based Authentication (FBA) with SharePoint 2010

















August 11th, 2010 at 10:06 pm
Thanks mate. Going to my "to reference in a bit"-list.
August 12th, 2010 at 4:51 am
:D
October 26th, 2010 at 11:22 pm
Thanks for the posting. It was really helpful. I was trying to find a sample or a solution of the code itself where one would access a SQL Server database for the Username and Password. Have you seen one in your explorations or can you perhaps share one? Any more help would be greatly appreciated.
October 27th, 2010 at 7:56 am
@Phillip: unfortunately I don't have such code sample as this is something that is covered by the out-of-the-box SQL Membership Provider provided with ASP.NET.
January 12th, 2011 at 11:53 pm
GetUser(string, bool) is not implemented in the OOB SharePoint Claims auth membership provider
September 4th, 2011 at 11:01 am
hi mastykarz, thanks for the post, I wonder if there is any custom membership management system for sharepoint or asp.net. Because related db logic is hard for current membership managemet systems
September 13th, 2011 at 3:28 pm
Bayram,
I've used the SharePoint 2010 FBA pack on codeplex with some simple modification here and there for our purposes. http://sharepoint2010fba.codeplex.com/
There is also another project on Codeplex that I thought was simple to use for user administration outside of SharePoint called MyWSAT. http://mywsat.codeplex.com/
One thing to note is that you need to be mindful as to how SharePoint links an FBA user to a user in its UserInfo table.
Hope this helps, Phil