Bonjour à tous,
Je suis actuellement sur du développement C# sous SharePoint plus précisément sur des authentifications via LDAP mais aussi des habilitations via une base SQL.
Il me faut donc par conséquent un MemberShipProvider Custom et un RoleProviderCustom.
Voici le code de mon RoleProvider :
et la classe associé Data :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 using System; using System.Collections.Generic; using System.Text; using System.Web.Security; using System.Data.SqlClient; using System.Configuration; using Microsoft.Office.Server.Security; namespace MyRoleProviderSQL { public class CustomProvider: RoleProvider { private string pApplicationName = "site1"; public override string[] GetAllRoles() { string[] listName; listName = Data.GetGroups(); return listName; } public override string ApplicationName { get { return pApplicationName; } set { pApplicationName = value; } } public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { throw new Exception("The method or operation is not implemented."); } public override string[] FindUsersInRole(string roleName, string usernameToMatch) { throw new Exception("The method or operation is not implemented."); } public override string[] GetRolesForUser(string username) { throw new Exception("The method or operation is not implemented."); } public override string[] GetUsersInRole(string roleName) { throw new Exception("The method or operation is not implemented."); } public override bool IsUserInRole(string username, string roleName) { throw new Exception("The method or operation is not implemented."); } public override bool RoleExists(string roleName) { throw new Exception("The method or operation is not implemented."); } public override void AddUsersToRoles(string[] usernames, string[] roleNames) { throw new Exception("The method or operation is not implemented."); } public override void CreateRole(string roleName) { throw new Exception("The method or operation is not implemented."); } public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { throw new Exception("The method or operation is not implemented."); }
ayant signé ma dll et l'ayant injecté dans le fichier web.config:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Data.SqlClient; namespace MyRoleProviderSQL { public class Data { internal static string[] GetGroups() { string[] listRoles; string conString = "Data Source=localhost;Initial Catalog=WSS_DynamicGroups;Integrated Security=True"; string request = @" SELECT DISTINCT NAME FROM DBO.GROUPS "; SqlConnection oSql = new SqlConnection(conString); SqlCommand oSqlCommand = new SqlCommand(request, oSql); oSql.Open(); SqlDataReader reader = oSqlCommand.ExecuteReader(); ArrayList listName = new ArrayList(); try { while (reader.Read()) { listName.Add(reader.GetValue(0).ToString()); } reader.Close(); oSql.Close(); if (listName.Count > 0) { listRoles = new string[listName.Count]; for (int i = 0; i < listName.Count; i++) { listRoles[i] = listName[i].ToString(); } } else { listRoles = new string[0]; } } catch (Exception exception) { throw new Exception("MyRoleProvider.GetAllRoles : " + exception.Message); } return listRoles; } } }
lors de ma connexion j'obtiens le message d'erreur suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <connectionStrings> <add name="sqlWSS_DynamicGroups" connectionString="Data Source=localhost;Initial Catalog=WSS_DynamicGroups;Integrated Security=true;" /> </connectionStrings> ........................ <roleManager enabled="true" defaultProvider="MyRoleProviderSQL"> <providers> <clear /> <add connectionStringName="sqlWSS_DynamicGroups" applicationName="/" name="MyRoleProviderSQL" type="MyRoleProviderSQL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=471a5a30d4f2db89" /> </providers>
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Partager