Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Changing profile provider at runtime

Reply
Thread Tools

Changing profile provider at runtime

 
 
=?Utf-8?B?andhbGxpcw==?=
Guest
Posts: n/a
 
      10-17-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change Profile Provider during runtime? briandre ASP .Net 0 08-17-2011 10:30 AM
<profile><properties> with no Profile class Steven ASP .Net 5 10-24-2008 07:23 PM
Visual Studio 2008 asp.net web administration>profile: "The profile wasn't created"? Andy B ASP .Net 0 05-03-2008 05:15 PM
Want to profile monitor for Fuji Frontier ICC profile? Lynn Digital Photography 9 09-08-2005 12:17 PM
Java Web Start app icons keep going in user profile not All Users profile Brad Java 1 07-19-2005 02:10 AM



Advertisments