multiple profile providers in single web application

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi:

I have been trying to create a web application that provides suport
for two membership/profile databases: one for private users and one
for another set of users. These tw user have a totally different set
of profile attributes.

I added the following code to my web.config (under system.web):

<membership defaultProvider="PortalMembershipProvider">
<providers>
<remove name="PortalMembershipProvider"/>
<remove name="PublicMembershipProvider"/>
<add name="PortalMembershipProvider"
type="System.Web.Security.SqlMembershipProvider..."
connectionStringName="LocalSqlServer" .../>
<add name="PublicMembershipProvider"
type="System.Web.Security.SqlMembershipProvider..."
connectionStringName="PublicUserProfiles" .../>
</providers>
</membership>
<profile defaultProvider="PortalProfileProvider">
<providers>
<remove name="PortalProfileProvider"/>
<remove name="PublicProfileProvider"/>
<add name="PortalProfileProvider"
connectionStringName="LocalSqlServer" .../>
<add name="PublicProfileProvider"
connectionStringName="PublicUserProfiles" .../>
</providers>
<properties>
<add provider="PortalProfileProvider" name="FirstName"
type="System.String" serializeAs="Xml"/>
<add provider="PortalProfileProvider" name="LastName"
type="System.String" serializeAs="Xml"/>
<group name="PhoneNumbers">
<add provider="PublicProfileProvider" name="Phone"
type="System.String" serializeAs="Xml"/>
<add provider="PublicProfileProvider" name="Fax"
type="System.String" serializeAs="Xml"/>
</group>
</properties>
</profile>
<roleManager defaultProvider="PortalRoleProvider" enabled="true">
<providers>
<add name="PortalRoleProvider"
connectionStringName="LocalSqlServer" .../>
<add name="PublicRoleProvider"
connectionStringName="PublicUserProfiles" .../>
</providers>
</roleManager>

All connection string names and values have been verified.

I try to add a user via the Membership API, targeting a specific
provider from above, I use the following code:
MembershipCreateStatus status;
user =
Membership.Providers["PortalMembershipProvider"].CreateUser(username,
password, email, "", "", true, Guid.NewGuid(), out status);
This works without issue.

I do the same ting for adding the new user to a role:

Roles.Providers["PortalRoleProvider"].AddUsersToRoles(userStringArray,
roleStringArray);
This works without issue as well.

Now here is the problem. When I try to perform a similar action to
add a profile for the new user, I use the following code:
section =
(ProfileSection)WebConfigurationManager.GetSection("system.web/
profile");
profile.Providers["PortalProfileProvider"].Initialize(

user.UserName,

section.Providers["PortalProfileProvider"].Parameters
);

I recieve an error stating that the profile provider "reference is not
set to an instance of an object."

Is there any way to get around this?

Best Regards,
Mike
 
Back
Top