ASP.NET: user membership package with user table

I recently started redoing ASP.NET MVC, but this question should apply to classic ASP.NET as well. For what it's worth, I'm not very good at authentication forms and membership providers.

I am trying to write my own MembershipProvider, which will be connected to my own user table in my database. My user table contains all basic user information, such as user names, passwords, password salts, email addresses, etc., as well as information such as first name, last name and country of residence.

As far as I understand, the standard way to do this in ASP.NET is to create a user table without additional information, and then a “profile” table with additional information. However, this is not very good for me, because whenever I need to access this additional information, I need to make one additional database query to get it.

I read in the book "Pro ASP.NET 3.5 in C # 2008" that having a separate table for profiles is not a good idea if you need to access the profile table very often and have many different pages on your site.

Now for the problem in question ... As I said, I am writing my own custom subclass MembershipProvider, and so far so good, but now I realized that CreateUserdoesn't allow me to create users as I would like. The method accepts only a fixed number of arguments, and their name, surname and country of residence are not part of them.

So, how do I create an entry for a new user in my user table without this information in CreateUsermine MembershipProvider?

+3
source share
2 answers

, , CreateUser CustomMembershipUser ( MemberhipUser) . , , CustomMembershipProvider .

+3

, . , , CreateUser, , . , , . :

string username = .../ retrieve username here

Membership.CreateUser(username , password, email);

ProfileBase newProfile = Profile.Create(username); //since the user has just been created, all properties will be blank

//set all entered properties
newProfile.SetPropertyValue("MyProp1", myProp1Value);
... 
newProfile.SetPropertyValue("MyPropN", myPropNValue);

newProfile.Save();

, ASP.NET , .

+2

Source: https://habr.com/ru/post/1742115/


All Articles