ProfileCommon.Create creates user with wrong apllicationID (provider)

N

news.microsoft.com

I have this code that should save a user with a specific applicationID:

protected void btnSaveUser_Click(object sender, EventArgs e)
{
string username = this.txtUsername.Text;
string firstname = this.txtFirstname.Text;
string lastname = this.txtLastname.Text;
string password = this.txtPassword.Text;
string email = this.txtEmail.Text;
int siteId = int.Parse(this.txtSiteId.Text);

MembershipCreateStatus status;
MembershipProvider mp = Membership.Providers[siteId.ToString()];
MembershipUser user = mp.CreateUser(username, password, email, null,
null, true, null, out status);

ProfileCommon p = (ProfileCommon)ProfileCommon.Create(user.UserName,
true);
p.FirstName = firstname;
p.LastName = lastname;
p.Save();

if (status == MembershipCreateStatus.Success)
{
// party!
}
}

In web.config I have 2 different applications (providers) like this:

<membership defaultProvider="1" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="1" applicationName="1"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnString" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"/>
<add name="2" applicationName="2"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnString" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"/>
</providers>
</membership>
<roleManager defaultProvider="1" enabled="false" cacheRolesInCookie="false"
cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/"
cookieRequireSSL="false" cookieSlidingExpiration="true"
cookieProtection="All" createPersistentCookie="false" maxCachedResults="25">
<providers>
<clear />
<add name="1" applicationName="1" connectionStringName="ConnString"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="2" applicationName="2" connectionStringName="ConnString"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
<profile enabled="true" defaultProvider="1">
<providers>
<clear/>
<add name="1" applicationName="1"
type="Microsoft.Samples.SqlStoredProcedureProfileProvider"
connectionStringName="ConnString" setProcedure="setCustomProfileData"
readProcedure="getCustomProfileData" />
<add name="2" applicationName="2"
type="Microsoft.Samples.SqlStoredProcedureProfileProvider"
connectionStringName="ConnString" setProcedure="setCustomProfileData"
readProcedure="getCustomProfileData" />
</providers>
<properties>
<add name="FirstName" defaultValue="[null]"
customProviderData="FirstName;nvarchar;50"/>
<add name="LastName" defaultValue="[null]"
customProviderData="LastName;nvarchar;50"/>
<add name="Age" type="int" customProviderData="Age;int;1"/>
</properties>
</profile>


If siteID=2 (this.txtSiteId.Text) then the users shall have applicationID=2.
It works when running mp.CreateUser();

But, when running ProfileCommon.Create() the default applicationID from
web.config is used (1), and a new user is created in the aspnet_users tabell
with applicationID 1. The profiledata is then related to this user that
should never been created, not the correct user with applicationID=2.

How can I programmatically set the correct provider (applicationID) when
saving profiledata (ProfileCommon.Create())?

Thanks for all tips!!!
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top