2009-11-15 2 views

Répondre

1

Il est un peu un hack, mais ici je configurer les rôles pour les services d'application client:

ClientRoleProvider crp = new ClientRoleProvider(); 
// Initialize 
NameValueCollection crp_config = new NameValueCollection(); 
crp_config.Add("serviceUri", "www.mydomain.com/Role_JSON_AppService.axd"); 
crp_config.Add("cacheTimeout", 5); 
crp_config.Add("honorCookieExpiry", 300); 
crp.Initialize("ClientRoleProvider", crp_config); 

//RoleProviderCollection 
RoleProviderCollection rpc = new RoleProviderCollection(); 
rpc.Add(crp); 
rpc.SetReadOnly(); 

//Roles 
BindingFlags enuBindingFlags = BindingFlags.NonPublic | BindingFlags.Static; 
Type objRoleType = typeof(Roles); 
objRoleType.GetField("s_Initialized", enuBindingFlags).SetValue(null, true); 
objRoleType.GetField("s_InitializeException", enuBindingFlags).SetValue(null, null); 
objRoleType.GetField("s_Enabled", enuBindingFlags).SetValue(null, true); 
objRoleType.GetField("s_CookieName", enuBindingFlags).SetValue(null, ".ASPXROLES"); 
objRoleType.GetField("s_CacheRolesInCookie", enuBindingFlags).SetValue(null, false); 
objRoleType.GetField("s_CookieTimeout", enuBindingFlags).SetValue(null, (int)30); 
objRoleType.GetField("s_CookiePath", enuBindingFlags).SetValue(null, "/"); 
objRoleType.GetField("s_CookieRequireSSL", enuBindingFlags).SetValue(null, false); 
objRoleType.GetField("s_CookieSlidingExpiration", enuBindingFlags).SetValue(null, true); 
objRoleType.GetField("s_CookieProtection", enuBindingFlags).SetValue(null, CookieProtection.All); 
objRoleType.GetField("s_Domain", enuBindingFlags).SetValue(null, null); 
objRoleType.GetField("s_CreatePersistentCookie", enuBindingFlags).SetValue(null, false); 
objRoleType.GetField("s_MaxCachedResults", enuBindingFlags).SetValue(null, (int)25); 
objRoleType.GetField("s_Provider", enuBindingFlags).SetValue(null, crp); 
objRoleType.GetField("s_Providers", enuBindingFlags).SetValue(null, rpc); 
0

De http://msdn.microsoft.com/en-us/library/5k850zwb.aspx

Roles.CreateRole("members"); 
Roles.CreateRole("manager"); 

Roles.AddUserToRole("JoeWorden", "manager"); 
string[] userGroup = new string[2]; 
userGroup[0] = "JillShrader"; 
userGroup[1] = "ShaiBassli"; 
Roles.AddUsersToRole(userGroup, "members"); 

bâton dans global.asax (Application_Start est probablement votre meilleur pari) et votre oncle Bob.

+0

Mais avec vous répondez, je dois encore web.config avec quelque chose comme: Nestor

Questions connexes