ProfileCommon.Create creates user with wrong apllicationID (provider)

Discussion in 'ASP .Net Security' started by news.microsoft.com, Dec 11, 2008.

  1. 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!!!
    news.microsoft.com, Dec 11, 2008
    #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. Ian

    vs.net creates doctype wrong?

    Ian, Jun 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    469
  2. Calavera

    Correct Import for ProfileCommon?

    Calavera, Jan 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,129
    Calavera
    Jan 23, 2006
  3. =?Utf-8?B?THlubmU=?=
    Replies:
    6
    Views:
    3,315
    paul1868
    Aug 11, 2007
  4. =?Utf-8?B?UGhpbA==?=

    CS0433: The type 'ProfileCommon' exists in both

    =?Utf-8?B?UGhpbA==?=, May 30, 2006, in forum: ASP .Net
    Replies:
    9
    Views:
    26,401
    Jim707
    Aug 3, 2008
  5. Carlo Razzeto
    Replies:
    1
    Views:
    354
    Akram
    Nov 10, 2006
Loading...

Share This Page