By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Dynamic Membership Provider

P: n/a
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("SQLConnect ionString").ConnectionString
= "super-secret connection string for production"
Case Else

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

Thanks for your input,
Ryan

Aug 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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]

<ry*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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("SQLConnect ionString").ConnectionString
= "super-secret connection string for production"
Case Else

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

Thanks for your input,
Ryan

Aug 22 '06 #2

P: n/a
Thanks for responding so quickly Ken. That did help greatly.

Have a great day,
Ryan
Ken Cox [Microsoft MVP] wrote:
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]

<ry*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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("SQLConnect ionString").ConnectionString
= "super-secret connection string for production"
Case Else

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

Thanks for your input,
Ryan
Aug 24 '06 #3

P: n/a

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

"ry*********@gmail.com" wrote:
Thanks for responding so quickly Ken. That did help greatly.

Have a great day,
Ryan
Ken Cox [Microsoft MVP] wrote:
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]

<ry*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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("SQLConnect ionString").ConnectionString
= "super-secret connection string for production"
Case Else
>
ConfigurationManager.ConnectionStrings("SQLConnect ionString").ConnectionString
= "super-secret connection string for development"
End Select
>
Thanks for your input,
Ryan
>

Aug 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.