Bug #73880 Roles.AddUserToRole throws foreign key exception.
Submitted: 10 Sep 2014 20:48 Modified: 3 Feb 2015 6:40
Reporter: Ashish Khadloya Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.9.3 OS:Windows (2008 r2)
Assigned to: CPU Architecture:Any
Tags: Roles.AddUserToRole, simplemembership provider

[10 Sep 2014 20:48] Ashish Khadloya
Description:
Cannot add user to roles using SimpleMembershipRole provider.
When you create a user and try to add role to it it throws foreign key voilation exception.
After further investigation i tried the same method after deleting foreign key 
UsersInRoles_Role on webpages_usersinroles table and i could see e7 getting added to this table for roleID.

How to repeat:
Just create a user and call Roles.AddUserToRole method
[10 Sep 2014 20:50] Ashish Khadloya
Sorry for Typo 
When i call the method Roles.AddUserToRole it add 67 to roleID column in webpages_usersinroles.
[29 Dec 2014 5:00] Chiranjeevi Battula
Hello Ashish Khadloya,

Thank you for the bug report.
How you are going to add data into roles and users tables.
Could you please list out the steps you tried out at your end? Please provide repeatable test case in order for us to confirm this issue at our end.

Thanks,
Chiranjeevi.
[29 Dec 2014 10:45] Ashish Khadloya
Hi Chiranjeevi,

I downloaded the source and figure out 2 issues related to Simple membership provider as below:

In MySql.Web --> MySqlSimpleRoleProvider.cs Line.no 495  "return (int)role[0];" should be replaced to "return (int)roleid[0];"

Another issue i found in Resetting password  as below:

MySql.Web --> MySqlSimpleMembershipProvider.cs Line.no 387 "if (token != null)"
should be replaced with " if (token == null)"

Hope this helps.

Thanks,
Ashish
[29 Dec 2014 13:26] Chiranjeevi Battula
Hello Ashish Khadloya,

Thank you for your feedback.
first we have to insert data into roles table then after add role to the user.

Thanks,
Chiranjeevi.
[29 Dec 2014 14:24] Ashish Khadloya
Hi Chiranjeevi,

I have inserted data tinto roles table and then tried to add to the user but as mentioned below

In MySql.Web --> MySqlSimpleRoleProvider.cs Line.no 495  "return
(int)role[0];" should be replaced to "return (int)roleid[0];"

Instead of returning role id the above code returns the first character of the role name passed in as parameter. Example if the role name passed in is ADMIN the method will return 65. To reproduce the issue just call GetRoleId method from unit test and pass it any role name and it will return the first charector's ASCII code of the role name.

Thanks,
Ashish
[5 Jan 2015 20:54] Omar Elabd
This issue is also related to the bug i submitted ( 75397 ).
I have the same issue with it returning 65 ( "Administrator" Role as well ). It seems like the GetRoleId method is not implemented correctly please see the implementation i posted on issue #75397 for a sample correct implementation.
[3 Feb 2015 6:40] Chiranjeevi Battula
Hello Ashish Khadloya,

Thank you for your feedback.
based on internal discussion with dev's, this bug will be fixed in Bug #75397.

Thanks,
Chiranjeevi.