2

I am developing an MVC 4 application. I am working on the membership authentication and profile module, and I am a bit confused.

I am confused because it seems that there ar TWO sets of Authorization/Profile modules working behind the scenes:

Short Version

There are TWO sets of tables for Authorization: one created when you create a new MVC 4 Internet application The second is created when you run aspnet_regsql. Data is saved and feteched from the two sets in a confusing way.

How are the two sets related: What is saved where? Why are Users created in the two sets? etc.

Long Version

Set 1

I created a new MVC 4 Internet project. It was generated with the ability to register users and create roles. The database that was automatically generated contained the following tables: Users, Roles, UserInRoles, Memebership, Profiles. There were no stored procedures. The Authorization worked OK: Users data and roles were correctly saved in Users, Roles and UserInRoles tables.

Set 2

I then moved on tp add Profile for the site users. I followd Joel's answer. When running the code hit this line: AccountProfile.CurrentUser.FullName = "Snoopy"; I received this error:

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

I ran aspnet_regsql against the database created earlier, and the expected set of aspnet_ tables and stored procedure was created. Tested my code again. This time it worked OK and the profile property was saved OK to the aspnet_Profile table (whic is to be expected).

In the next step I created a new user. The user was created in BOTH Users and aspnet_Users tables (with different UserId values) -- please see here picture 1

Added the property FullName=Snoopy to his profile.

Running Membership.GetUser().ProviderUserKey returns the UserId from table Users. Running AccountProfile.CurrentUser.FullName returns "Snoopy". Please see here picture 2.

This very surprising because it means that somehow the system knows how to relate a record from table Users to a record in table aspnet_Profile where the UserId field is from table aspnet_users. BTW, I verified that table Profiles is empty so the value was not feteched from there.

So what is going on here? Is this behavior the expected behavior? Or is Jole's answer wrong in the sense that there some other (better?) way to implement Profile in an MVC 4 application, and what I did is to throw a wrench in the works?

Community
  • 1
  • 1
Dror
  • 1,406
  • 12
  • 15

1 Answers1