How to Change Membership provider during runtime

Discussion in 'ASP .Net' started by =?Utf-8?B?QmFsYWpp?=, Jul 6, 2006.

  1. Hi All,

    Can I use more than one membership provider for a given website? I
    understand only one of them could be default one. If yes, then how to
    programmatically access the other membership provider? For e.g. lets say I
    have a SQLMembership provider and OracleMembership provider. SQL would be my
    default provider. During authentication, based on the value of an additional
    parameter in the login screen, I need to validate against SQL or Oracle db.
    Is this feasible?

    I found this on MSDN

    “You can also configure multiple membership providers, which allows you to
    select a membership provider at run time based on application requirements.
    For example, for business reasons your membership information might be in
    separate regional databases. By configuring multiple membership providers
    that each interact with a different regional database, you can direct
    membership calls to the appropriate provider for different users.â€

    http://msdn2.microsoft.com/en-us/library/sx3h274z.aspx


    Any idea on how to switch Membership provider during runtime?

    Thanks for tip,
    -Balaji NJL
     
    =?Utf-8?B?QmFsYWpp?=, Jul 6, 2006
    #1
    1. Advertising

  2. Hi Balaji,

    You need to make sure all the membership providers are listed in the
    web.config file, like this:

    <membership defaultProvider="Mydefaultprovider">
    <providers >
    <clear/>
    <add connectionStringName="ASPNETDBConnectionString1"
    name="MyOracleprovider"
    type="System.Web.Security.OracleMembershipProvider"/>
    <add connectionStringName="ASPNETDBConnectionString2"
    name="Mydefaultprovider" type="System.Web.Security.SqlMembershipProvider"/>
    </providers>
    </membership>

    Then in your code, reference the one you want to use:

    Dim mbr As MembershipProvider
    mbr = Membership.Providers.Item("MyOracleprovider")
    ' mbr.CreateUser(....
    Response.Write(mbr.GetType)

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]


    "Balaji" <> wrote in message
    news:...
    > Hi All,
    >
    > Can I use more than one membership provider for a given website? I
    > understand only one of them could be default one. If yes, then how to
    > programmatically access the other membership provider? For e.g. lets say I
    > have a SQLMembership provider and OracleMembership provider. SQL would be
    > my
    > default provider. During authentication, based on the value of an
    > additional
    > parameter in the login screen, I need to validate against SQL or Oracle
    > db.
    > Is this feasible?
    >
    > I found this on MSDN
    >
    > "You can also configure multiple membership providers, which allows you to
    > select a membership provider at run time based on application
    > requirements.
    > For example, for business reasons your membership information might be in
    > separate regional databases. By configuring multiple membership providers
    > that each interact with a different regional database, you can direct
    > membership calls to the appropriate provider for different users."
    >
    > http://msdn2.microsoft.com/en-us/library/sx3h274z.aspx
    >
    >
    > Any idea on how to switch Membership provider during runtime?
    >
    > Thanks for tip,
    > -Balaji NJL
    >
    >
     
    Ken Cox [Microsoft MVP], Jul 6, 2006
    #2
    1. Advertising

  3. That helps, Thanks a lot.

    "Ken Cox [Microsoft MVP]" wrote:

    > Hi Balaji,
    >
    > You need to make sure all the membership providers are listed in the
    > web.config file, like this:
    >
    > <membership defaultProvider="Mydefaultprovider">
    > <providers >
    > <clear/>
    > <add connectionStringName="ASPNETDBConnectionString1"
    > name="MyOracleprovider"
    > type="System.Web.Security.OracleMembershipProvider"/>
    > <add connectionStringName="ASPNETDBConnectionString2"
    > name="Mydefaultprovider" type="System.Web.Security.SqlMembershipProvider"/>
    > </providers>
    > </membership>
    >
    > Then in your code, reference the one you want to use:
    >
    > Dim mbr As MembershipProvider
    > mbr = Membership.Providers.Item("MyOracleprovider")
    > ' mbr.CreateUser(....
    > Response.Write(mbr.GetType)
    >
    > Let us know if this helps?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    >
    >
    > "Balaji" <> wrote in message
    > news:...
    > > Hi All,
    > >
    > > Can I use more than one membership provider for a given website? I
    > > understand only one of them could be default one. If yes, then how to
    > > programmatically access the other membership provider? For e.g. lets say I
    > > have a SQLMembership provider and OracleMembership provider. SQL would be
    > > my
    > > default provider. During authentication, based on the value of an
    > > additional
    > > parameter in the login screen, I need to validate against SQL or Oracle
    > > db.
    > > Is this feasible?
    > >
    > > I found this on MSDN
    > >
    > > "You can also configure multiple membership providers, which allows you to
    > > select a membership provider at run time based on application
    > > requirements.
    > > For example, for business reasons your membership information might be in
    > > separate regional databases. By configuring multiple membership providers
    > > that each interact with a different regional database, you can direct
    > > membership calls to the appropriate provider for different users."
    > >
    > > http://msdn2.microsoft.com/en-us/library/sx3h274z.aspx
    > >
    > >
    > > Any idea on how to switch Membership provider during runtime?
    > >
    > > Thanks for tip,
    > > -Balaji NJL
    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?QmFsYWpp?=, Jul 6, 2006
    #3
  4. =?Utf-8?B?QmFsYWpp?=

    amanam

    Joined:
    Dec 20, 2007
    Messages:
    1
    amanam, Dec 21, 2007
    #4
  5. =?Utf-8?B?QmFsYWpp?=

    JeffRausch

    Joined:
    Jul 23, 2008
    Messages:
    2
    Can I set DefaultProvider during Runtime

    Hello

    I know this post is a little old but hopefully someone knows the answer to this.

    I realize that you can access other membership providers by using Membership.Providers.Item("providername") but what I would like to do is change the default provider during runtime.

    Let me try to explain how I'm going to be using it. I am setting up a hosted solution so users will be getting to our login page using a different URL for each client, a user will use the URL for the client they are with. Some clients will be using AD for authentication and others will be using our own custom internal authentication. I check the url that they are using and then am able to find which membershipprovider I should use for validating that user. What I would like to do is every time I need to do something with the user (change password, validate, etc), instead of having to check the url and hit the database to find out what membership provider I need I would like to set the DefaultProvider on session load or application load or something like that so my developers can simply do Membership.ChangePassword without my having to worry about what MembershipProvider to use.

    I've tried to search on setting the default provider in global.asax or anywhere else without any success.

    Thanks,
    Jeff
     
    JeffRausch, Jul 23, 2008
    #5
  6. =?Utf-8?B?QmFsYWpp?=

    JeffRausch

    Joined:
    Jul 23, 2008
    Messages:
    2
    Oops, Ignore my question above. I realize now why you can't change the default provider otherwise it would mess up in a multi-threading situation.

    Thanks.
     
    JeffRausch, Jul 24, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sloan
    Replies:
    5
    Views:
    1,519
    sloan
    Jun 4, 2006
  2. Alias
    Replies:
    0
    Views:
    976
    Alias
    Feb 15, 2007
  3. sloan
    Replies:
    1
    Views:
    521
    Chad Scharf
    Jul 3, 2007
  4. briandre
    Replies:
    0
    Views:
    1,063
    briandre
    Aug 17, 2011
  5. Jason
    Replies:
    0
    Views:
    138
    Jason
    Dec 8, 2005
Loading...

Share This Page