By: TwitterButtons.com

Recent blog posts

User login

Home | Blogs | Stephane Eyskens's blog

SPClaimsAuthMembershipProvider casting error

Hi,

If like me you experienced the above error, don't lose time wondering what the hell is going on. When you use FBA, once the FBA authentication gets completed, a SPCLaim token is issued and that's why, the following line of code (usual in 2007):

would throw the following invalid cast error:

Unable to cast object of type Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider to ...

You could of course workaround this exception by using this syntax:

but you would end up with a NULL value in return.

So, the solution is just to target your FBA provider like this:

and it's likely to work better :).

Happy coding!

MyMembershipProvider provider = Membership.Providers["Name of your provider as defined in the web.config"] as MyMembershipProvider;