If you need to perform some action on FBA user in your Sharepoint site where claims authentication is used from outside of Sharepoint context (e.g. from console application) you may face with the following issue: when you will call web.EnsureUser(userName) method it will throw exception:
Specified user ‘username’ not found
There are several things which have to be done in order to make it possible to work with FBA users without Sharepoint context with claims based authentication:
1. Fake HTTP context after you get instance of SPWeb:
2. Use user name in full claims format, i.e.:
where instead of mymembershipprovider and username you should use your own membership provider name and user name.
3. The most tricky thing: from web.config of your FBA site zone you need to copy the following sections to the app.config of your console application:
Here is the full working C# code which allows to get FBA user from console application: