ASP.NET Membership error when using Membership with Azure Storage
- I'm getting an error when I attempt to display the users of my application. The error is shown in the twitpic link below.
I'm using a web role and am using the azure storage along with the membership provider for azure storage. This error just started with no changes made to the code. Any ideas? I'm wondering if somehow the mixed case is causing confusion.
http://twitpic.com/ocvpv
MVP in ASP.NET - ASPInsider - Author - Otherwise I am a loser.
Answers
- It's a bug, with the AspProvider, you probably have double usernamesex: WallyM and wallymI'm not sure to who to report it!
- Marked As Answer byYi-Lun LuoMSFT, ModeratorTuesday, November 17, 2009 11:38 AM
- azure-bright, thanks for reporting this issue. I've verified TableStorageMembershipProvider allows case-sensitive username (it use's PartitionKey to store username, which is case-sensitive). But ASP.NET membership does not allow that. I will report this problem to our product team.
Wally, if you're sure you've hit this problem, I suggest you to go through the Membership table, and delete any usernames that are only different in case. Then please modify your code to store all the username in lower case, and when you retrieve the username, you also do a case-insensitive comparison.
If for some reason, you cannot delete existing users (for example, a lot of customers have already registered on your web site), I'm afraid the only workaround is to hack ASP.NET's MembershipUserCollection class to allow case-sensitive username. For example, in the GetAllUsers method, you can add the following code:
MembershipUserCollection users = new MembershipUserCollection();
var _IndicesField = users.GetType().GetField("_Indices", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
object _Indices = _IndicesField.GetValue(users);
var _keycomparerField = typeof(System.Collections.Hashtable).GetField("_keycomparer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
_keycomparerField.SetValue(_Indices, StringComparer.InvariantCulture);
TableStorageDataServiceContext svc = CreateDataServiceContext();
Note I haven't tested the code thoroughly, and I'm not sure if this hack will cause side effects. Use the code at your own risks.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byYi-Lun LuoMSFT, ModeratorTuesday, November 17, 2009 11:37 AM
All Replies
- It's a bug, with the AspProvider, you probably have double usernamesex: WallyM and wallymI'm not sure to who to report it!
- Marked As Answer byYi-Lun LuoMSFT, ModeratorTuesday, November 17, 2009 11:38 AM
- azure-bright, thanks for reporting this issue. I've verified TableStorageMembershipProvider allows case-sensitive username (it use's PartitionKey to store username, which is case-sensitive). But ASP.NET membership does not allow that. I will report this problem to our product team.
Wally, if you're sure you've hit this problem, I suggest you to go through the Membership table, and delete any usernames that are only different in case. Then please modify your code to store all the username in lower case, and when you retrieve the username, you also do a case-insensitive comparison.
If for some reason, you cannot delete existing users (for example, a lot of customers have already registered on your web site), I'm afraid the only workaround is to hack ASP.NET's MembershipUserCollection class to allow case-sensitive username. For example, in the GetAllUsers method, you can add the following code:
MembershipUserCollection users = new MembershipUserCollection();
var _IndicesField = users.GetType().GetField("_Indices", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
object _Indices = _IndicesField.GetValue(users);
var _keycomparerField = typeof(System.Collections.Hashtable).GetField("_keycomparer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
_keycomparerField.SetValue(_Indices, StringComparer.InvariantCulture);
TableStorageDataServiceContext svc = CreateDataServiceContext();
Note I haven't tested the code thoroughly, and I'm not sure if this hack will cause side effects. Use the code at your own risks.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byYi-Lun LuoMSFT, ModeratorTuesday, November 17, 2009 11:37 AM


