Xenetrix
Xenetrix

Reputation: 339

Custom Profile duplicates user information

I created a custom Profile class using ProfileBase, but I've been having problems inserting information. I created a user using the asp's register wizard, and in my CreateUserWizard1_CreatedUser method I wrote the code that takes care of adding the information in Profile.

ProfileUser pc = ProfileUser.GetUserProfile(UserName);
pc.FirstName = name.Text;
pc.LastName = lastname.Text;
pc.Save();

My ProfileUser custom class is:

namespace CancerApp
{

        public class ProfileUser : ProfileBase
        {
            [SettingsAllowAnonymous(false)]
            public string FirstName
            {
                get { return base["FirstName"] as string; }
                set { base["FirstName"] = value; }
            }

            [SettingsAllowAnonymous(false)]
            public string LastName
            {
                get { return base["LastName"] as string; }
                set { base["LastName"] = value; }
            }

            public static ProfileUser GetUserProfile(string username)
            {
                return Create(username) as ProfileUser;
            }

            public static ProfileUser GetUserProfile()
            {
                return Create(Membership.GetUser().UserName) as ProfileUser;
            }
        }

}

My Web.config:

   <profile inherits="CancerApp.ProfileUser">
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" />
      </providers>
    </profile>

What's the problem? When pc.Save() runs makes duplicated information in aspnet_Users table with different ApplicationID and UserId.

enter image description here

Any Idea ?

Update: this only occurs when I publish the application, but when I use start debugging all's ok

Upvotes: 2

Views: 263

Answers (2)

Uzay
Uzay

Reputation: 879

profile and membership application name should be same in your web.config file:

  <profile defaultProvider="SqlProvider" inherits="YourNamespace.AccountProfile">
  <providers>
    <clear />
    <add name="SqlProvider"
         type="System.Web.Profile.SqlProfileProvider"
         connectionStringName="memConnStr"
         **applicationName="MyApplication"/>**
  </providers>
</profile> 
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">     
  <providers>
    <clear />
    <add
      name="SqlProvider"
      type="System.Web.Security.SqlMembershipProvider"
      connectionStringName="memConnStr"
      **applicationName="MyApplication"**
      enablePasswordRetrieval="false"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="false"
      requiresUniqueEmail="true"
      minRequiredNonalphanumericCharacters="0"
      passwordFormat="Hashed" />        
  </providers>
</membership>

Upvotes: 1

Xenetrix
Xenetrix

Reputation: 339

Today I just solve the problem. It was creating another user because he was not assigning a name to the application.

It is absolutely necessary to assign a name's app for the profile function properly. Since no name the system creates a name from the application automatically and there the reason for the creation of another ApplicationId.

Upvotes: 0

Related Questions