We are working on an ASP.NET Web Forms application using ASP.NET Membership for user related operations. When a user is created in the application, we add him to two roles, a main and a sub role, as per the below code snippet.
Roles.AddUserToRole(userName, mainRoleName);
if (mainRoleName == "Test")
{
Roles.AddUserToRole(userName, subRoleName);
}
Rarely, we face an issue where the user gets added to the subRoleName but is not part of the mainRoleName. Is there any specific reason for this to happen and anyone faced similar issues like the one mentioned?
You have to understand a forum cannot answer this question. The code you've shared uses variables for the role names; mainRoleName and subRoleName. The community has no idea how these role variables are set or if it is possible for the variable to contain
values that do not match roles in the database.
When I consider troubleshooting steps, I would look at either the mainRoleName does not equal "Test" or the subroleName does not exist in the database. I'm pretty sure the code will throw an exception if the role does not exist in the database. Do you
have proper exception handling enable and are not hiding exceptions? Are you logging error messages?
None
0 Points
3 Posts
Adding roles using AddUserToRole(string username, string roleName) does not work sometimes
Dec 28, 2020 02:10 PM|Shriram Sankaran|LINK
We are working on an ASP.NET Web Forms application using ASP.NET Membership for user related operations. When a user is created in the application, we add him to two roles, a main and a sub role, as per the below code snippet.
Rarely, we face an issue where the user gets added to the subRoleName but is not part of the mainRoleName. Is there any specific reason for this to happen and anyone faced similar issues like the one mentioned?
All-Star
52091 Points
23221 Posts
Re: Adding roles using AddUserToRole(string username, string roleName) does not work sometimes
Dec 28, 2020 02:31 PM|mgebhard|LINK
You have to understand a forum cannot answer this question. The code you've shared uses variables for the role names; mainRoleName and subRoleName. The community has no idea how these role variables are set or if it is possible for the variable to contain values that do not match roles in the database.
When I consider troubleshooting steps, I would look at either the mainRoleName does not equal "Test" or the subroleName does not exist in the database. I'm pretty sure the code will throw an exception if the role does not exist in the database. Do you have proper exception handling enable and are not hiding exceptions? Are you logging error messages?
All-Star
48280 Points
17981 Posts
Re: Adding roles using AddUserToRole(string username, string roleName) does not work sometimes
Dec 28, 2020 03:03 PM|PatriceSc|LINK
Hi,
Or could it be that the role "Test" is later removed from this user but that the subRoleName is left?