Dynamic Membership Provider

R

ryan.mclean

Hello everyone,

I am wondering, can the membership provider be changed at runtime?
Perhaps the connectionStringName?

I would like to use a different database based on the server the site
is on.

I suppose that a custom provider could be used to accomplish this, is
there another way?

It would be great to do the following:
Select Case strEnvironment
Case "PRD"

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for production"
Case Else

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for development"
End Select

Thanks for your input,
Ryan
 
K

Ken Cox [Microsoft MVP]

Hi Ryan,

Put your default and alternate membership providers (and their connection
strings) in the web.config file, like this:

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

<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("MyAlternateprovider")
' mbr.CreateUser(....
Response.Write(mbr.GetType)

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
R

ryan.mclean

Thanks for responding so quickly Ken. That did help greatly.

Have a great day,
Ryan

Hi Ryan,

Put your default and alternate membership providers (and their connection
strings) in the web.config file, like this:

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

<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("MyAlternateprovider")
' mbr.CreateUser(....
Response.Write(mbr.GetType)

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

Hello everyone,

I am wondering, can the membership provider be changed at runtime?
Perhaps the connectionStringName?

I would like to use a different database based on the server the site
is on.

I suppose that a custom provider could be used to accomplish this, is
there another way?

It would be great to do the following:
Select Case strEnvironment
Case "PRD"

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for production"
Case Else

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for development"
End Select

Thanks for your input,
Ryan
 
G

Guest

Hello,

this is a great solution. I was looking around quite a while for something
like this.
But I have one big problem:

All the membership methods now need all parameters :-(
The Default Membership-Provider accepts a variety of overloaded methods.

example:

' this is the normal way with the defaultprovider - and it works fine:
newUser = Membership.CreateUser(UserName, Password)

Now with a dynamic provider,you must provide all Parameters:

Dim mbr As MembershipProvider = Membership.Providers.Item("TestProvider")

mbr.CreateUser(UserName, Password, "","","",True, ProviderUserKey, Status)

Is there any solution for this Problem ?

Thanks in advance !

Kind Regards,
Michael



Thanks for responding so quickly Ken. That did help greatly.

Have a great day,
Ryan

Hi Ryan,

Put your default and alternate membership providers (and their connection
strings) in the web.config file, like this:

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

<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("MyAlternateprovider")
' mbr.CreateUser(....
Response.Write(mbr.GetType)

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

Hello everyone,

I am wondering, can the membership provider be changed at runtime?
Perhaps the connectionStringName?

I would like to use a different database based on the server the site
is on.

I suppose that a custom provider could be used to accomplish this, is
there another way?

It would be great to do the following:
Select Case strEnvironment
Case "PRD"

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for production"
Case Else

ConfigurationManager.ConnectionStrings("SQLConnectionString").ConnectionString
= "super-secret connection string for development"
End Select

Thanks for your input,
Ryan
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,310
Latest member
FaustoMont

Latest Threads

Top