Clarification on customising the MembershipUser

Jun 21, 2012 at 11:37 AM

Hi Omid,

This is a really awesome project.  Very much what I was hoping for.  I have a question though on using it with customizations.  Sorry I know you wrote a very long and detailed Readme, but I ended up not sure how to make the full customisations.

If I wanted a user, supported by the Membership Framework (ie: works with roles, login controls etc), but using your framework, and customised with additional data, how would I do it?

The reason I ask is that in the readme example you give, you give an example for a User class, but it doesn't inherit from anything like MembershipUser.  However you did give an example on the discussions here, where you have an object that does inherit from MembershipUser http://efmembership.codeplex.com/discussions/296060

I need to be able to support things like password reset and security questions, roles, etc, most of the default features.  Please don't think I want you to spend all your valuable time on this, just a couple of pointers as to which class I need and how they must inherit would be more than enough, I'll work the rest out.

Thanks again!!

Adam.

Coordinator
Jun 22, 2012 at 2:33 PM

Hi,

It was very grate for me to have a comment from you.

Your entity framework model must not inherit from anything because it uses Code First,

Since you have more columns than Membership you cannot use MembershipUser class and you must create a class and inherit from it and you must add your customize properties to it.

Since AutoMapper doesn't recognize your custom properties, you must create a mapper for your membership.

For example, download the source code and go to "OmidID.Web.Security.EFMembershipProvider\Default\OldEf" directory and take a look at those codes

 

Best,
Omid Mafakher

Jun 23, 2012 at 9:03 PM

Hi Omid,

Thank you so much for your reply.  I'm afraid I'm still finding a couple of things difficult to understand, so hopefully you can bear with me.

In your example in the source, you have an EFUser class and a custom Membership class.  Why can't these be the same thing?  Why don't you have your EFUser class inherit from MembershipUser (built-in .net version) and just use that?  Why is there a custom Membership user class that has three extra properties?

I hope that makes sense?

Thanks,

Adam.

Coordinator
Jun 26, 2012 at 4:04 PM

Hi.

You must have a pure c# class(Model) for you entity framework (code first). EFUser class is a model of your database. search tutorial for code first in google and see how it work.

In second step you need a custom MembershipUser class because you must return it in your custom membership provider methods. this class have some built-in property and you want to add your custom properties, like FirstName.

var member = (MyCustomMembershipUser)Membership.GetUser("Omid");
var firstName = member.FirstName;

 

Best,
Omid Mafakher