Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

web.EnsureUser from a Class in SharePoint project with Custom Membership provider throws exception

$
0
0

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




Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>