Windows Azure Platform Developer Center > Microsoft Visual Studio 2010 Beta 2 Forums > Windows Azure > ASP.NET Membership error when using Membership with Azure Storage
Ask a questionAsk a question
 

AnswerASP.NET Membership error when using Membership with Azure Storage

  • Friday, November 06, 2009 9:32 PMWally McClureMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Sunday, November 08, 2009 12:30 AMazure-bright Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It's a bug, with the AspProvider, you probably have double usernames 
    ex:  WallyM and wallym
    I'm not sure to who to report it!
  • Monday, November 09, 2009 5:33 AMYi-Lun LuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.

All Replies

  • Sunday, November 08, 2009 12:30 AMazure-bright Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    It's a bug, with the AspProvider, you probably have double usernames 
    ex:  WallyM and wallym
    I'm not sure to who to report it!
  • Monday, November 09, 2009 5:33 AMYi-Lun LuoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.