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

2
  • 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. Commented Aug 29, 2011 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. Commented Aug 29, 2011 at 14:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for all your helpful suggestions. I have found this link 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
Apologies, didn't realise you actually had to click on the check mark to accept an answer. I thought saying thank you was enough!
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.