How create role to put in the database?

余生颓废 提交于 2019-12-06 16:41:40

You don't.

If you're using ASP.NET's membership framework, you don't touch it using LinqToSql. You use ASP.NET's membership framework.

This is how you might acomplish something like that. I am not sure why you would want to create a role for every user though, kind of defeats the purpose of roles. Anyways something like this will work:

// Check User exists
if (Membership.GetUser("admin") == null)
    Membership.CreateUser("admin", "pass", "admin@domain.com");            

// Check Role exists or create
if (!Roles.RoleExists("AdminRole"))
    Roles.CreateRole("AdminRole");

// Check Users in Roles
if (!Roles.IsUserInRole("admin", "AdminRole"))
    Roles.AddUserToRole("admin", "AdminRole");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!