c# Roles.GetRolesForUser() occasionally returns partial result

Multi tool use


c# Roles.GetRolesForUser() occasionally returns partial result
The web application is using MySql as the membership provider.
The code is pretty simple: in the controller it reads user roles and passes the result to the view; However, this function Roles.GetRolesForUser() occasionally returns partial result, for example, for user with roles A,B,C, sometimes it only gets [A] back (interestingly it's always A that's returned if it happens).
Any idea how that happens? Clues are welcome, thanks!
More info: We are using ProxySql in front of our db server; it looks like when it's disabled, the problem is gone.
Web.config:
<membership hashAlgorithmType="HMACSHA256" defaultProvider="MySQLMembershipProvider">
<providers>
<clear/>
<remove name="MySQLMembershipProvider"/>
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.9.9.0, Culture=neutral, PublicKeyToken="*****" applicationName="*****" description="membership" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" enablePasswordRetrieval="False" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="10" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="^.*(?=.{10,})(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^=_*&)({};:?,-+]).*$"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="MySQLRoleProvider">
<providers>
<clear/>
<add applicationName="*****" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
<remove name="MySQLRoleProvider"/>
<add applicationName="*****" description="" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.9.9.0, Culture=neutral, PublicKeyToken=*******"/>
</providers>
</roleManager>
The controller is basically:
ViewModel.DebugString = string.Join(",",Roles.GetRolesForUser());
The cshtml looks like:
<script>console.log("@Model.DebugString");</script>
Some more exception:
The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField columns)
at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.Close()
at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar()
at MySql.Web.Security.MySQLMembershipProvider.GetUserId(MySqlConnection connection, String username)
at MySql.Web.Security.MySQLMembershipProvider.GetUser(String username, Boolean userIsOnline)
at System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline)
@mjwills Thanks for the heads-up. The problem is random, and the code is working most of the time, so I'm not sure what needs to be added. I've added more details.
– Jack.W
yesterday
Do any of the role names have single or double quotes in them?
– mjwills
yesterday
@mjwills Thanks for the comment. No, the only thing they have other than alphabetical characters is underscore.
– Jack.W
yesterday
Please show the configuration of the
RoleProvider
via the roleManager
tag in web.config
. Does it also have a writeExceptionsToEventLog
which can be set to true
?– pfx
yesterday
RoleProvider
roleManager
web.config
writeExceptionsToEventLog
true
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It would be awesome if you could provide a Minimal, Complete, and Verifiable example.
– mjwills
yesterday