"User cannot be found." error when creating an FBA site programmatically through Windows application or a console application.
When we create an FBA site through console app or a windows app, we need to have the membership provider and the role provider information within App.Config file. It would be with the same structure as we have in the web.config file of SharePoint WebApplication.
App.Config for your Windows/Console application should be like this.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="SharePoint">
<section name="PeoplePickerWildcards" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<SharePoint>
<PeoplePickerWildcards>
<clear />
<add key="AspNetSqlMembershipProvider" value="%" />
<add key="LdapMembership" value="%" />
</PeoplePickerWildcards>
</SharePoint>
<system.web>
<membership>
<providers>
<add
name="LdapMembership"
type="Microsoft.Office.Server.Security.LDAPMembershipProvider, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
server="youservername"
port="389"
useSSL="false"
userDNAttribute="distinguishedName"
userNameAttribute="sAMAccountName"
userContainer="DC=yourdomainname,DC=corp,DC=yourcontroller,DC=com" userObjectClass="person" userFilter="(|(ObjectCategory=group)(ObjectClass=person))" scope="Subtree" otherRequiredUserAttributes="sn,givenname,cn" />
</providers>
</membership>
<roleManager defaultProvider="AspNetWindowsTokenRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".PeopleDCRole">
<providers>
<add
name="LdapRole"
type="Microsoft.Office.Server.Security.LDAPRoleProvider, Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"
server="yourservername"
port="389"
useSSL="false"
groupContainer="DC=yourdomainname,DC=corp,DC=yourdomaincontroller,DC=com"
groupNameAttribute="cn"
groupMemberAttribute="member"
userNameAttribute="sAMAccountName"
dnAttribute="distinguishedName"
groupFilter="(ObjectClass=group)"
scope="Subtree" />
</providers>
</roleManager>
</system.web>
</configuration>