Mono Support Role Management (Closed)

Viewed 18959 time(s), 5 post(s), 9/13/2011 10:00:54 AM - by manvir.kaur
9/13/2011 10:00:54 AM
3046 Reputation 388 Total posts

I have only 3 roles in my application of admin, user and vendor. In my registration page, user can register as a user or vendor by selecting role from a dropdown.I have deleted all the existing roles from aspnet_Roles and given these 3 roles there. Now, on the registration page, i'm trying to assign the selected role to user using this code :

Roles.AddUserToRole(this.UserName, ddlUserType.SelectedItem.Text);

Here ddlUserType.SelectedItem.Text contains the text, which is there in RoleName field from aspnet_Roles table

This code is called after Account has been created.

However, its giving me an error of the role '' was not found

Can you pls tell me, where is the system looking for role, as it is there in db?Is it looking for the role in web.config file?

Also, i can see some roles in Web.config file as follows:

<add key="AdministratorRoles" value="Administrators;" />
<add key="NewsPublisherRoleName" value="Publishers" />
<add key="CalendarAdministratorRoles" value="Administrators,Publishers" />
<add key="AdManagerRoles" value="AdManager,Administrators" />
<add key="BlogAdministratorRoles" value="Administrators,Publishers" />

And one default user role as follows:

<add key="DefaultUserRoles" value="Users" />

What do i need to do with these roles in web.config file as i do not need them. Also i do not need any default role. In my application, user need to select the role from drop down list at the time of registration.
Shall i remove these roles from web.config file?

1
9/13/2011 10:10:48 AM
15993 Reputation 2214 Total posts

Hi,

as I can see everything you are doing should be ok, except maybe one thing and it is related to the DropDown binding and the selected items. When you check the ddlUserType.SelectedItem.Text does it have a value ? Can you provide us with the code-behind source so we can take a look at the whole user control ?

Roles that you have mentioned in the web.config can be removed if you don't need them, but note you need to remove the Roles from the value part of the setting, we still need the setting it self e.g.

<add key="NewsPublisherRoleName" value="Publishers" />
Change to
<add key="NewsPublisherRoleName" value="" />

As for the default role you need one role as a default role which is used in the MonoX CMS to put the new users in that role and to check the user permissions. So set the DefaultUserRoles setting to your default role.

If you need anything else let us know.

Regards

2
9/13/2011 10:20:24 AM
3046 Reputation 388 Total posts

ddlUserType.SelectedItem.Text has a value (Vendor) which matches with the value of RoleName field in aspnet_Roles table.
For testing purpose I've also tried this code as follows:

Roles.AddUserToRole(this.UserName, 'Vendor');

It gives me same error.

3
9/13/2011 10:24:25 AM
3046 Reputation 388 Total posts

Do i also need to re-generate code from LLBLGen Pro, after making any changes in data in Sql Server, like role name?

4
9/13/2011 10:33:44 AM
15993 Reputation 2214 Total posts

Hi,

no you don't need to regenerate the LLBLGen when you change the data, only when you change the structure. Static objects Roles and Membership are a part of the ASP.NET Membership provider structure and it isn't related to LLBLGen it may be related to Cache optimization used in MonoX layer or misconfiguration of the Membership provider. Can you please send us a web.config file so we can check the configuration ?

Please post your questions to your priority support forum so we can track it there, as I'm closing this public forum topic. Thanks

5
This is a demo site for MonoX. Please visit Mono Software for more info.