0

I'm using ASP.NET MVC3 with EF Code First. I'm new to both tech, so please be gentle!

I have a requirement that I will need additional properties for the User (such as company name, first/last name etc). I also need to be able to store the Membership information in databases other than SQL Server. So I am looking into custom membership user and provider classes. Except I just do not know how that would work with EF Code First.

My custom user class is extending MembershipUser. And I have a custom extension of the MembershipProvider class. Within the provider, I'd like to use my DBContext class to get User information, but I can't seem to get it working correctly. Please can somebody guide me?

Thanks

SimpleUser
  • 1,341
  • 2
  • 16
  • 36
  • 1
    Can you please provide more details as to why it is not working? It seems as you have already done the hard part (not so hard, extending the membership classes). The rest should be pretty straight forward. – AJC Aug 29 '11 at 14:42
  • Just my .02, I stopped using .net membership long ago. I find it easier to use my own User class and Auth service that uses the FormsAuth method which bypasses the .Net Membership provider altogether. This allows you to use whatever properties you want and more flexibility for persistence. – Justin Soliz Aug 29 '11 at 14:47

1 Answers1

1

This is how I get the user in my implementation:

public override System.Web.Security.MembershipUser GetUser(string username, bool userIsOnline)
{
    MyUser user = MyUserController.get(username);
    if (user == null)
        return null;
    MembershipUser mUser = new MembershipUser("MyMembershipProvider", 
        user.Login, 
        user.Id, 
        user.Email, 
        null, null, true, false, 
        user.CreateDate, 
        DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

    return mUser;
}

Is this what you are looking for?

Hope it helps.

AJC
  • 1,853
  • 1
  • 17
  • 28
  • Thanks for all your helpful suggestions. I have found this link http://codefirstmembership.codeplex.com/ which was quite useful in guiding me towards where I wanted to go. In terms of marking questions as answered or answering my own questions, I have actually done both when the answers were helpful or I found something out myself. I do like to thank people who take their precious time out to help:-) Thank you – SimpleUser Aug 29 '11 at 18:28
  • Apologies, didn't realise you actually had to click on the check mark to accept an answer. I thought saying thank you was enough! – SimpleUser Aug 29 '11 at 18:36
  • @chandinipt - Thats ok... no problem... Thanks for the link, I'll check it out and see if it offers something I can use my own implementation lacks to see if I change how I do it. – AJC Aug 29 '11 at 19:00