I have a SharePoint site in 2013, configured to use a Custom Membership Provider (inherited from MembershipProvider class). I have an empty SharePoint project with just a class in it. In that class, inside a method, I have used the following piece of code. But it is throwing an exception saying "The specified user could not be found", when it encounters the web.EnsureUser method. Can anyone please help? The DLL is deployed to GAC and I even tried adding a safe control entry to the SharePoint site's web.config file, but still, it is throwing the same exception.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string strSiteURL = "<site URL>";
string encUserName = EncodeUsername(userName, strSiteURL); <-- This gives the Claims encoded user name in the format i:0#.f|CustMemProvider|username
using (SPSite site = new SPSite(strSiteURL))
{
using (SPWeb web = site.OpenWeb())
{
MembershipProvider mp = Membership.Providers["CustMemProvider"]; <-- This returns null as well.
SPUser user = web.EnsureUser(encUserName); <-- This line throws exception.
}
}
});Ven