Changing profile provider at runtime

Discussion in 'ASP .Net' started by =?Utf-8?B?andhbGxpcw==?=, Oct 17, 2006.

  1. 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
     
    =?Utf-8?B?andhbGxpcw==?=, Oct 17, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2V0ZG90bmV0?=

    Custom profile provider asp.net 2.0

    =?Utf-8?B?Z2V0ZG90bmV0?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    569
    =?Utf-8?B?Z2V0ZG90bmV0?=
    Jul 6, 2005
  2. Brad
    Replies:
    1
    Views:
    1,156
    Roedy Green
    Jul 19, 2005
  3. Andy B
    Replies:
    0
    Views:
    539
    Andy B
    May 3, 2008
  4. Steven
    Replies:
    5
    Views:
    503
    Steven
    Oct 24, 2008
  5. briandre
    Replies:
    0
    Views:
    1,067
    briandre
    Aug 17, 2011
Loading...

Share This Page