I am writing an application in C # using WPF and the Entity Framework. It is necessary to authorize the user and, depending on his role, to display the functionality available to him. With the display, everything is clear, but how to make the authorization and getting the role? such roles will be in the system:
//Создаем логины context.Database.ExecuteSqlCommand("CREATE LOGIN BakeryAdmin WITH PASSWORD = 'Admin' CREATE LOGIN BakeryManager WITH PASSWORD = 'Manager' CREATE LOGIN BakeryUser WITH PASSWORD = 'User'"); //Создаем пользователей context.Database.ExecuteSqlCommand( "CREATE USER BakeryAdmin FOR LOGIN BakeryAdmin CREATE USER BakeryManager FOR LOGIN BakeryManager CREATE USER BakeryUser FOR LOGIN BakeryUser"); //Создаем роли context.Database.ExecuteSqlCommand("CREATE ROLE Admins AUTHORIZATION db_accessadmin CREATE ROLE Managers AUTHORIZATION db_datawriter CREATE ROLE Users AUTHORIZATION db_datareader"); //Добавляем пользователей к ролям context.Database.ExecuteSqlCommand( "EXEC sp_addrolemember 'Admins', 'BakeryAdmin' EXEC sp_addrolemember 'Managers', 'BakeryManager' EXEC sp_addrolemember 'Users', 'BakeryUser'"); Naturally, there may be other users, but the roles will remain the same. Actually briefly questions: How to transfer login / password to the connection string? How to get user roles?