MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Programmicaly add rules ?  (Mono Support )

14396 put(a) pogledan, 6 odgovor(a) 2.5.2012. 16:53:03Kreirao(la) shawndg
shawndg

shawndg

2.5.2012. 16:53:03
Hi Guys,

I want to add rules during registration and so far I did try setting it in the web config but that did not work.. maybe because my rule is custom..

The following code, does not work but I think it is close.

//add default isband rule to band profiles..

IEnumerable<MonoSoftware.MonoX.API.Role> Rules = new IEnumerable<MonoSoftware.MonoX.API.Role>();
Rules = SecurityUtility.UserRoleIds(userId);

MonoSoftware.MonoX.API.RoleAdapter ruleadb = MonoSoftware.MonoX.API.RoleAdapter.GetInstance();
ruleadb.ChangeUserRoles(userId, Rules);

any help ?

thanks
Ovaj sadržaj još nije ocijenjen. 
1871 Reputacija 252 Ukupno objava
pajo

pajo

3.5.2012. 6:50:26
Hi shawndg,

If you're trying to add new roles to the user, you should try this

var userRoles = MonoSoftware.MonoX.API.RoleAdapter.GetInstance().GetUserRoles(userId).ToList();
 
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "YourRole"));
 
MonoSoftware.MonoX.API.RoleAdapter.GetInstance().ChangeUserRoles(userId, userRoles);
Ovaj sadržaj još nije ocijenjen. 
629 Reputacija 83 Ukupno objava
shawndg

shawndg

3.5.2012. 17:14:05
The code does not work.. =/

Error 19 'MonoSoftware.MonoX.API.RoleAdapter' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'MonoSoftware.MonoX.API.RoleAdapter' could be found (are you missing a using directive or an assembly reference?) C:\#PittsburghSceneProd\CustomParts\BandRegister\MembershipEditor.ascx.cs 119 76 Portal
Error 18 'System.Linq.IQueryable<MonoSoftware.MonoX.API.Role>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Linq.IQueryable<MonoSoftware.MonoX.API.Role>' could be found (are you missing a using directive or an assembly reference?) C:\#PittsburghSceneProd\CustomParts\BandRegister\MembershipEditor.ascx.cs 118 99 Portal


Note im using .net 4.0 and the latest MonoX
Ovaj sadržaj još nije ocijenjen. 
1871 Reputacija 252 Ukupno objava
shawndg

shawndg

3.5.2012. 17:16:27
Missing..

using System.Linq;

my bad..
Ovaj sadržaj još nije ocijenjen. 
1871 Reputacija 252 Ukupno objava
shawndg

shawndg

3.5.2012. 17:45:41
still no dice.. =/

//add default isband rule to band profiles..
var userRoles = MonoSoftware.MonoX.API.RoleAdapter.GetInstance().GetUserRoles(userId).ToList();
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "isband"));
MonoSoftware.MonoX.API.RoleAdapter.GetInstance().ChangeUserRoles(userId, userRoles);

{"Object reference not set to an instance of an object."}
happens on line ..
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "isband"));


Ovaj sadržaj još nije ocijenjen. 
1871 Reputacija 252 Ukupno objava
imarusic

imarusic

10.5.2012. 12:05:32
Hi shawdg,

Did you try with DefaultUserRoles property in web.config? By setting that property newly registered user should be added in role(s) defined by that property.

Have you checked that your role exist in database?

Regards.
Ovaj sadržaj još nije ocijenjen. 
3016 Reputacija 428 Ukupno objava