问题
i wish create a role for each user after that the user authenticate(login) to access to the application i will give some role to and save the role on the database. I will make an example with the database "aspnet.mdf" and Linq toSql to store data but before i need know how create role in c#(WPF) and after created i wish add roles on the database so doing i can assign for each user the right role that i wish . DO you have some idea how do it right??? I will use the database "aspnet.mdf" as example because i see it good just to test my application (i need this feature to develop a project).
Thanks a lot.
Nice Regards,
Bye
回答1:
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.
回答2:
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");
来源:https://stackoverflow.com/questions/557791/how-create-role-to-put-in-the-database