I am working on a generic solution (for both SP2010 and SP2013) for any kind of farm. I need to access the Membership APIs in my code from a Console App / Windows Service. Using the SPSite object (then SPWebApplication and IisSettings), I am able to get the Membership and Role Provider names in my code dynamically, without hardcoding them. Now to get the MembershipProvider instance, I use the Membership.Providers[mpName]. But this code doesn't work, unless the appropriate entries are made into the application config file. I cannot make these entries, because my code has to work for different end customers of my customer and hence I want to drive this through code. Of course, I can take the connection string as input, but I want to control everything else through code?

To put it in simple terms, is there a way to get the MembershipProvider instance without configuration elements, but only through code? Please note that I am not talking about removing the config entries from the STS Web.config or SP Web.config. I am only talking about removing these entries from my custom application config and controlling them through my application code.

Can anyone please help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.