Implementing User Membership Rights

I am trying to implement a custom membership provider and want to change the GetUser method. The problem is that GetUser returns MemberhipUser, and I want to return MyMembershipUser, which has two additional properties, FirstName and LastName. I can create a new method in my member provider that returns MyMembershipUser, but then I think this will not make any sense.

How can I do it?

+4
source share
3 answers

This will defeat the purpose of the Membership classes. Do something similar if you need to access other properties:

 var user = Membership.GetUser(userName, true) as MyMembershipUser; 

Indeed, you should have a separate Profile class that handles things that MembershipUser does not provide.

 var profile = Profile.GetProfile(Membership.GetUser(userName, true)); 
+4
source

You need to contact your profile provider. check this link you have SqlStoredProcedureProfileProvider and SqlTableProfileProvider, so you have the option to keep the profile data "clear" in the database, allowing you to query db whenever you want.

"you can implement all the necessary business logic in stored procedures to map profile data with your own database schema and database logic.

+2
source

If MemberhipUser is the base class of MyMembershipUser, then you can return instances of MyMembershipUser even if the return type of GetUser () is MemberhipUser and then, if necessary, return them to MyMembershipUser (but do you really need to do this?)

By the way, this is an example of polymorphism.

0
source

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


All Articles