468,256 Members | 1,431 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

Dynamic Membership Provider

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
3 3027
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
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

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.

Similar topics

3 posts views Thread by Morgan | last post: by
2 posts views Thread by John | last post: by
9 posts views Thread by Paul Keegstra | last post: by
4 posts views Thread by thomas | last post: by
4 posts views Thread by =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post: by
6 posts views Thread by Jonathan Wood | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.