Asp.Net mebership creates two users in aspnet_Users table

While using asp.net membership and roles you will see two seperate entries for same user in aspnet_Users table. But you will have a single entry for that user in aspnet_Membership table. The reason for that is you have set applicationName for your membership and roles provider in your web.config.

So if you want a single entry you need to set same value for applicationName attribute for both provider. Yes, this is true if you are using asp.net profile provider.

e.g. 

<membership>

<providers>

<add name="AspNetSqlMembershipProvider"

type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"

enablePasswordReset="true"

requiresQuestionAndAnswer="true"

applicationName="/myApp"

requiresUniqueEmail="false"

passwordFormat="Hashed" maxInvalidPasswordAttempts="5"

minRequiredPasswordLength="7"

minRequiredNonalphanumericCharacters="1"

passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

</providers>

</membership>

<profile>

<providers>

<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/myApp" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

</providers>

</profile>

<roleManager defaultProvider="AspNetSqlRoleProvider" enabled="true">

<providers>

<clear />

<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/myApp" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

</providers>

</roleManager>

 

Check this for more information on applicationName attribute.

Reference:

 

1 Comment

  • Thanks for this article. It solved my problem.

    The framework was creating two entries in aspnet_Users for each User,

    but only deleting one of them when I called Membership.DeleteUser.

    Now I have added the same applicationName to AspNetSqlRoleProvider (it was previously set to "/") and only one row is created in aspnet_Users. The row is correctly removed when deleting the user.

Comments have been disabled for this content.