Asp.Net mebership creates two users in aspnet_Users table

While using 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 profile provider.




<add name="AspNetSqlMembershipProvider"

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

connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"





passwordFormat="Hashed" maxInvalidPasswordAttempts="5"



passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>





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



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


<clear />

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




Check this for more information on applicationName attribute.



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.