Entries into dbo.Users, not dbo.aspnet_Users

steve_webber
steve_webber used Ask the Experts™
on
I have migrated some ASP.Net 2.0 code to ASP.Net 4.5 and am having a problem with adding users and roles. The new information is going into a table dbo.Users in the aspnetdb database rather than dbo.aspnet_Users as it used to. Why is this and how do I get it to work as before? Is there a new API I should be using?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Manoj PatilSr. Software Engineer

Commented:
Just replace this,

 <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

Open in new window


with this,


<membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>

Open in new window

Author

Commented:
This did not work. I created my aspnetdb database using aspnet_regsql.exe and all of the tables within the database so created have their names prefixed with "aspnet_". The views created reference the tables with these names. However, when I try to execute

      Roles.CreateRole("Administration")
      Membership.CreateUser("admin@appforms.com", "foobar123", "admin@appforms.com")
      Roles.AddUserToRole("admin@appforms.com", "Administration")

it creates new tables which do not have "aspnet_" at the beginning of the names. It places the new role in the dbo.Roles table and can't add the user because it is looking for dbo.aspnet_Roles (via the views which still reference dbo.aspnet_Roles).
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
It appears that the new user was added to the ado.aspnet_Users table, but the role was added to ado.Roles table and the error occurs trying to add the user to the role.
Manoj PatilSr. Software Engineer

Commented:
Can you specify the error.

Author

Commented:
The error returned was "The user 'admin@appforms.com' was not found." I assume this is because it was looking in dbo.Users instead of dbo.aspnet_Users.
The problem was that I should not have tried to use aspnet_regsql.exe at all. This is apparently all automatic with ASP.Net 4.5. I am using the web.config that was generated by default and it works fine. I'm not sure why it was referencing the aspnet_Roles table, and I'll try to figure this out.

Author

Commented:
I determined by myself that i was using an obsolete mechanism to create the membership database. It is created automatically, with different table names, with ASP.Net 4.5.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial