Duplicate user entries in aspnet_Users

Last post 10-18-2007 11:09 PM by xiaobing. 4 replies.

Sort Posts:

  • Duplicate user entries in aspnet_Users

    11-10-2006, 8:11 PM
    • Loading...
    • kreid
    • Joined on 10-19-2006, 12:15 PM
    • Posts 85

    Hi,

    I have noticed that there are duplicates of some users in my sql database.  Each pair of entries have different application IDs. For example, when I do the following, duplicate names are displayed for most of the existing users:

     

            foreach (MembershipUser user in Membership.GetAllUsers())
    {
    DropDownList1.Items.Add(user.UserName.ToString());
    }
     

    I suspect that this is something to do with the connections strings in web.config, but I don't know much about how this has to be formatted, apart from what has been generated or I have copied off the web.  I do know that the connection string should be "/" (??) but can be different if desired.  Here are the relevant parts of web.config, if anyone could explain what I have done wrong I would appreciate it.

      

     <roleManager enabled="true" />

    ...


    <membership defaultProvider="AspNetSqlProvider" userIsOnlineTimeWindow="5">
    <providers>
    <add name="AspNetSqlProvider" type="System.Web.Security.SqlMembershipProvider,
    System.Web,
    Version=2.0.3600.0,
    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1" passwordFormat="Hashed" description="Stores and retrieves membership data from
    the local Sql Server database"
    />

    </providers>
    </membership>

    ...

    <profile defaultProvider="SqlProfileProvider">
    <providers>
    <remove name="AspNetSqlProfileProvider"/>
    <add name="SqlProfileProvider"
    type="System.Web.Profile.SqlProfileProvider"
    connectionStringName="LocalSqlServer"/>
    </providers>
    <properties>
    <add name="FirstName" type="string"/>
    <add name="LastName" type="string"/>
    <add name="Company" type="string"/>
    <add name="SubIDs"
    type="System.Collections.Specialized.StringCollection" serializeAs="Xml" />
    </properties>
    </profile>
     
     
  • Re: Duplicate user entries in aspnet_Users

    11-11-2006, 10:42 AM
    Answer
    • Loading...
    • pkellner
    • Joined on 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,437
    • Moderator
      TrustedFriends-MVPs

    each application should have a different name:

    applicationName="/"

    should be something like applicationName="/MyApp1"

    Peter Kellner
    http://73rdstreet.com and blogging at
    http://PeterKellner.net
    MVP, ASP.NET
  • Re: Duplicate user entries in aspnet_Users

    03-01-2007, 9:31 AM
    • Loading...
    • RBrown
    • Joined on 06-25-2003, 7:55 PM
    • Posts 29
    Something is still not right with using a custom Sql Provider though.  I used the aspnet_regsql.exe utility to properly configure my SQL Server 2005 for Membership and Roles.  I setup my web.config provider section just like all the examples tell you to do:

    <

    membership defaultProvider="CustomizedMembershipProvider">
    <
    providers>
       <
    clear/>
          <
    add name="CustomizedMembershipProvider"
            
    type="System.Web.Security.SqlMembershipProvider"
            
    connectionStringName="SQLConnection"
            
    applicationName="WebSecurity"
            
    minRequiredPasswordLength="5"
            
    minRequiredNonalphanumericCharacters="0" />
    </
    providers>
    </
    membership>

     When I use the Web Administration Tool to create my users and roles, it has a bug in it somewhere that is causing it to create two different ApplicationIDs in the aspnet_Applications table.  This in turn causes the creation of duplicate users in the Membership and Users tables as soon as you assign roles to a user.  I think the bug has to do with the applicationName setting.  If my web app name is WebSecurity and I set my applicationName="WebSecurity", I will get two ApplicationIDs, one is WebSecurity, and the other is /WebSecurity.  This has to be  bug no?  Or should my provider definition include the backslash in front of the applicationName property?  Doesn't say to do this in the docs.  But I'll give that a shot.

    Anybody else dealing with this?  this is not happening in the ASPNETBD.mdf App_Data folder Membership configuration setting so I know it's a bug in the custom SQL provider implementation.

    Any help would be much apreciated.

    Thanks,
    Randy

  • Re: Duplicate user entries in aspnet_Users

    03-01-2007, 10:19 AM
    • Loading...
    • RBrown
    • Joined on 06-25-2003, 7:55 PM
    • Posts 29

    Well, it appears that the "/" in front of the applicationName property value is the culprit.  After changing this from:

    applicationName
    ="WebSecurity"
    to
    applicationName="/WebSecurity"

    the Membership system appears to now behave normally and does not duplicate the ApplicationID or users after assigning users to roles. 

    The other question I would have then is does the roleManager provider section require an applicationName property as well?

    Again, the "/" appears to have fixed the duplication problem, but was just wondering if the roleManager needs to specify an applicationName as well.

    Lastly, why don't the MS docs specify the need for the backslash? (http://msdn2.microsoft.com/en-us/library/whae3t94.aspx)

    Oh well, thanks.

  • Re: Duplicate user entries in aspnet_Users

    10-18-2007, 11:09 PM
    • Loading...
    • xiaobing
    • Joined on 01-24-2007, 4:19 AM
    • Posts 181

    Hi, I've the same problem. I have a list to show all the Roles.

    After changed the applicationName to "/appName", no more duplicate users created.

    However, even I do the same thing at roleManager provider (or even didn't provide the applicationName), it always auto generate the Roles "Administrator", "Consultant" and "Manager" which I never want it appear. Even I go to WebAdminTool to delete it (or delete from database), it will appear again after refreshing the page.  

    Please help, Thanks! 

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter