Changing profile provider at runtime

G

Guest

I have two systems, one for 'Test' and one for 'Live' and each has a Sql
Server.
When 'Test' code is published to 'Live' I currently have to edit connection
strings in web.config
to ensure that the live system does not access the test database and vice
versa.
This method is prone to error so for Membership and Roles, I have created
providers for Test and Live
and select the correct provider at runtime. (This will be achieved by
recognising the machine name of the Test server).
eg
MembershipProvider myMembershipProvider =
Membership.Providers["CustomAspNetSqlMembershipProvider"];
MembershipUser myMember = myMembershipProvider.GetUser(strUsername, true);

However, the same syntax does not seem to be available for Profile.
I need to select the profile provider at runtime, but the defaultProvider is
always used.

Extract from Web.config
<profile enabled="true" defaultProvider="CustomAspNetSqlProfileProvider"
automaticSaveEnabled="true">
<providers>
<clear />
<add name="CustomAspNetSqlProfileProvider"
connectionStringName="LiveSqlServer" applicationName="myApp"
type="System.Web.Profile.SqlProfileProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="LocalAspNetSqlProfileProvider"
connectionStringName="LocalSqlServer" applicationName="myApp"
type="System.Web.Profile.SqlProfileProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<properties>
<add name="Firstname"/>
<add name="Lastname"/>
<add name="Comments"/>
</properties>
</profile>


This code creates a ProfileCommon using the default provider
ProfileCommon mProfile = new ProfileCommon();
mProfile.Initialize("myUsername", true);

The following line fails because the 'Live' SQLServer is unavailable from
'Test'
TextBox1.Text = mProfile.Firstname;

How can the profile provider be specified at runtime?
On the 'Test' system, the LocalAspNetSqlProfileProvider should be used
On the 'Live' system, the CustomAspNetSqlProfileProvider should be used
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top