开发者

Asp.net MVC3 + Code First + Custom Membership Users and Provider classes?

开发者 https://www.devze.com 2023-04-01 01:17 出处:网络
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

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 gu开发者_Go百科ide me?

Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号