1

I would want to know if it is possible to set the default Membership provider (Membership.Provider) through code not through configuration file.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexander Beninski
  • 817
  • 3
  • 11
  • 24
  • What is the purpose of such manipulation? – Johnny_D Jul 12 '12 at 07:32
  • This might help. You can add them to the configuration file and then select which to run at runtime. I imagine you can also use your own custom class if you want instead (as long as it inherits from MembershipProvider of course)...http://stackoverflow.com/questions/10496647/set-active-membership-provider-programmatically – Theo Jul 12 '12 at 07:34
  • I think @Theo is onto your best bet. You could create a proxy membership provider that just utilizes your desired membership provider based on whatever your criteria might be. – Jaime Torres Jul 12 '12 at 12:01
  • My scenario is rather complicated. Thank you all for your answers I was just interested in setting the Membership.Provider through code somehow. Now that I know it cannot be set imperative I will try and search a work arround. Thank you. – Alexander Beninski Jul 12 '12 at 13:52

1 Answers1

1

It is not direct approach to your question. Instead, implement the custom membership provider, and use IoC container (for example, Enterprise Library Unity) to inject the desire class at run time.

For example,

public override MembershipUser GetUser(string username, bool userIsOnline)
{
   var user = IoC.Resolve<IUserService>().GetUserByUsername(username, userIsOnline);
}
Community
  • 1
  • 1
Win
  • 61,100
  • 13
  • 102
  • 181