如何管理使用SimpleMembership配置文件? [英] How do I manage profiles using SimpleMembership?

查看:206
本文介绍了如何管理使用SimpleMembership配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于该网络模板的ASP.NET MVC 4个网站。我使用,我设置了该模板SimpleMembership。

I have an ASP.NET MVC 4 site based off the internet template. I am using the SimpleMembership which i set up with that template.

我可以修改已creted对我来说,用户表,但我不能确定为正确的方法来修改附加字段我加入。我想全名,电子邮件等,并让他们添加到用户表,但似乎没有办法通过SimpleMembership WebSecurity更新。*的静态方法。

I can modify the Users table which has been creted for me but I am unsure as to the "correct" way to modify the extra fields I have added. I want Fullname, Email etc and have added them to the user table but there appears no way to update through the SimpleMembership WebSecurity.* static methods.

您应该只更新自己使用EF的SimpleMembership API之外吗?这些属性。

Are you supposed to just update those properties yourself using EF outside of the SimpleMembership API?

推荐答案

1 - 你需要启用迁移,prefereably用的EntityFramework 5

1 - You need to enable migrations, prefereably with EntityFramework 5

2 - 将您

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "EmailAddress", autoCreateTables: true); 

在你YourMvcApp /迁移/ Configuration.cs类的种子法

to your Seed method in your YourMvcApp/Migrations/Configuration.cs class

    protected override void Seed(UsersContext context)
    {
        WebSecurity.InitializeDatabaseConnection(
            "DefaultConnection",
            "UserProfile",
            "UserId",
            "UserName", autoCreateTables: true);

        if (!Roles.RoleExists("Administrator"))
            Roles.CreateRole("Administrator");

        if (!WebSecurity.UserExists("lelong37"))
            WebSecurity.CreateUserAndAccount(
                "lelong37",
                "password",
                new {Mobile = "+19725000000", IsSmsVerified = false});

        if (!Roles.GetRolesForUser("lelong37").Contains("Administrator"))
            Roles.AddUsersToRoles(new[] {"lelong37"}, new[] {"Administrator"});
    }

现在EF5将负责创建用户配置表,这样做后,你将调用WebSecurity.InitializeDatabaseConnection只与已创建的用户配置表中注册SimpleMembershipProvider,也tellling SimpleMembershipProvider这列是用户ID和用户名。我也呈现出了如何添加用户,角色为例,以自定义用户配置性能/例如字段的种子法两者关联用户的手机(号码)和IsSmsVerified

Now EF5 will be in charge of creating your UserProfile table, after doing so you will call the WebSecurity.InitializeDatabaseConnection to only register SimpleMembershipProvider with the already created UserProfile table, also tellling SimpleMembershipProvider which column is the UserId and UserName. I am also showing an example of how you can add Users, Roles and associating the two in your Seed method with custom UserProfile properties/fields e.g. a user's Mobile (number) and IsSmsVerified.

3 - 现在当你从包管理器控制台运行更新的数据库,EF5将提供您的表,你所有的自定义属性。

3 - Now when you run update-database from Package Manager Console, EF5 will provision your table with all your custom properties

有关其他参考资料,请参考本文来源与code:
<一个href=\"http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-$c$cfirst-and-custom-user-properties/\">http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-$c$cfirst-and-custom-user-properties/

For additional references please refer to this article with sourcecode: http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properties/

这篇关于如何管理使用SimpleMembership配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆