A little note to self about custom Membership and Role Providers and SharePoint 2010 Claims
Table of Contents
- Creating custom Membership and Role Providers
- Registering custom Membership and Role Providers with SharePoint 2010 Claims
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:
- GetUser(string, bool)
- GetUser(object, bool)
A custom Role Provider has to implement at least the following methods in order to work with SharePoint 2010:
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)
- 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:
brush: <system.web> <roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false"> <providers> <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=126.96.36.199, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <add name="MyRoleProvider" type="MyRoleProvider, MyAuth, Version=188.8.131.52, Culture=neutral, PublicKeyToken=0000000000000000"/> </providers> </roleManager> <membership defaultProvider="i"> <providers> <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <add name="MyMembershipProvider" type="MyMembershipProvider, MyAuth, Version=220.127.116.11, Culture=neutral, PublicKeyToken=0000000000000000"/> </providers> </membership> </system.web>
- 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