0
Hi all, 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
c# .net database linq-to-sql roles
flag edited Feb 17 '09 at 17:39
asked Feb 17 '09 at 17:14
JayJay
20416
69% accept rate
3 Answersoldest
newest
votes 2
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.
link|flag answered Feb 17 '09 at 17:18
Will
29.8k64283
Hi Will, that's mean that i cannot use the aspnet.mdf as example to write down data with Linq ToSQl?..i need that database only to make a test because i see it right ...when i will develop my project i will create my database of course..I don't wish use ASP.NET as i have not knowledge about it.:) – JayJay Feb 17 '09 at 17:47
Membership in ASP.NET is a complex framework that extends beyond the database itself. If you try to modify all your aspnet_ tables directly, you may not do it correctly, causing the framework to fail. Therefore, for membership, use the framework. Use LinqToSql for everything else. – Will Feb 18 '09 at 16:01
1
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", "[email protected]");
// 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");
link|flag answered Feb 17 '09 at 18:47
Kyle LeNeau
24518
0
Hi , maybe i'm not clear (sorry for that) i will explain better my idea, i will rewrite the same "aspnet.mdf" database on SqlServer after i will develop a test project using Linq ToSql to add username,password,role etc etc. (that's why i need develop my project in Linq ToSQl ) so i wish write down the role and with Linq toSql i will save the role on the database so doing i assign the role for each user as i wish.now i don't know how create the role in my project,i know how authenticate in the application with a login and after i get stuck....i have not idea how save the role on the database. If i 'm not clear please don't hesitate to ask me more news maybe i don't know how explain my purpose.
Have a nice day.
Nice regards
Bye
link|flag edited Feb 18 '09 at 7:01
answered Feb 18 '09 at 1:49
JayJay
20416
I'm sorry. What you're saying does not make sense. Try using Google to translate from your native language. – Will Feb 18 '09 at 18:58
No,don't worry ,i'm sorry as i have poor knowledge(just 4 months i began to programmer ,no school and else). I will repeat my question later trying to make me understand. Thanks a nd sorry for my bother. Bye ;) – JayJay Feb 19 '09 at 1:37
I am still not clear on why you need to use LINQ to SQL to manage the roles and not the built in .Net Membership and Role providers. In either case you will need a database, why not use SQL server for production and a SQLExpress db file for development. – Kyle LeNeau Feb 20 '09 at 16:18
Hi Kyle,i have a poor knowledge(just 5 month i m a programmer) so each advice is accepted .I will develop a project with Linq ToSql to store data to database and WpF as interface.I don't wish use Asp.Net as i have not knowledge about that.My goal is to assign roles to user's from databas – JayJay Feb 22 '09 at 17:10
Your Answer
JayJay,
I know this is an old thread.
I understand you're trying mimic the role based security that is available in Asp.Net 2.0. Unfortunately, Microsoft did not create this frame work in WPF. If you want to create login/role based security in WPF, you will have to write one from scratch. Create user table, setting table, login table, etc. You can probably create a simple login feature dumb down all the features. Good luck. community wiki JayJay, I know this is an old thread.
I understand you're trying mimic the role based security that is available in Asp.Net 2.0. Unfortunately, Microsoft did not create this frame work in WPF. If you want to create login/role based security in WPF, you will have to write one from scratch. Create user table, setting table, login table, etc. You can probably create a simple login feature dumb down all the features. Good luck.