Assigning Roles with MVC SimpleMembership

谁说我不能喝 提交于 2019-12-03 11:07:41
Ben Ripley

You need to use the Roles API to interact with the Roles. Something like the following should work:

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

if (!Roles.GetRolesForUser(model.UserName).Contains("Administrator"))
    Roles.AddUsersToRole(new[] { model.UserName }, "Administrator");
WebSecurity.InitializeDatabaseFile("SecurityDemo.sdf", "Users", "UserID", "Username", true);

CHeck out this website. It may be of some help. http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!