locked
Membership provider problem RRS feed

  • Question

  • Hello.

    I have a peculiar problem with my Azure deployment. First, allow me to describe what I'm trying to achieve.

    I have a project, ASP.NET/C# with MVC3, developed in VS 2010. I am using Azure SQL as storage for everything, as defined in Web.config

      <connectionStrings>
        <add name="DefaultConnection"
             connectionString="Server=tcp:MYINSTANCE.database.windows.net,1433;Database=MYDB;User ID=MYUSER@MYINSTANCE;Password=MYPASSWORD;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True"
          providerName="System.Data.SqlClient" />
      </connectionStrings>

    Authentication is done via the default membership provider

        <authentication mode="Forms">
          <forms loginUrl="~/Account/LogOn" timeout="2880" />
        </authentication>
        <membership defaultProvider="DefaultMembershipProvider">
          <providers>
            <clear />
            <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
          </providers>
        </membership>
        <profile defaultProvider="DefaultProfileProvider">
          <providers>
            <clear />
            <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
          </providers>
        </profile>
        <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
          <providers>
            <clear />
            <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
              type="System.Web.Security.WindowsTokenRoleProvider" />
            <add connectionStringName="DefaultConnection" applicationName="/"
              name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          </providers>
        </roleManager>

    I ran it initially from VS2010 and created a few users. All went well and after I was happy with the outcome of development I deployed the project to Windows Azure. The first thing I noticed was that I could not log in with any user, unless I used the password recovery method. No database errors, just invalid credentials. If I try to create the users again, it says they exist and password recovery works fine.

    To make matters even weirder, if I create a user using the Azure-deployed instance, I can log in fine with it from that side, but I can't log in with it from the instance I run in VS2010 unless I reset its password.

    Does anyone have any idea what is wrong?

    Looking forward to your replies.


    Sunday, May 27, 2012 6:43 AM

Answers

All replies

  • Hi,

    Can you access the SQL Azure data from SQL Azure user table normally, or only Membership can not works in SQL Azure? I suggest you use SqlMembershipProvider instead of DefaultMembershipProvider and have a try. Thanks.

    And here is a tutorial introduce how to migrate Membership from SQL Server to SQL Azure:

    http://niftyandcrackerjack.com/migrate-ms-sql-with-asp-membership-to-sql-azure/

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marked as answer by Arwind - MSFT Friday, June 1, 2012 10:14 AM
    Monday, May 28, 2012 8:42 AM
  • Hello Arwind,

    That is a very good walkthrough, but I'm not using MSSQL locally. In both cases (local through VS and deployed in cloud), the application uses the SQL Azure instance. The data is common to both cases.

    I will try to switch to SqlMembershipProvider and come back with the outcome. Thanks!

    Monday, May 28, 2012 9:42 AM
  • Hi,

    Thanks. If you have further testing result or issue, please inform me, thank you.

    BR,

    Arwind


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Monday, May 28, 2012 10:04 AM
  • Does anyone have any idea what is wrong?

    Looking forward to your replies.

    I'm wondering, did you ever solve this problem? I'm having the exact same problem with the Azure Web Role. If the app is deployed as a Azure Web Site, it works OK.

    Update: I registered a new user through the Azure deployment and then logged in to the SQL Azure. What I noticed is that the password hash for the new user is much shorter than it is for the other users. So it seems that after deploying the size to Azure, the hash algorithm changes... No idea yet how this could be solved.

    Tuesday, July 24, 2012 12:03 PM
  • I'm wondering, did you ever solve this problem? I'm having the exact same problem with the Azure Web Role. If the app is deployed as a Azure Web Site, it works OK.

    Update: I registered a new user through the Azure deployment and then logged in to the SQL Azure. What I noticed is that the password hash for the new user is much shorter than it is for the other users. So it seems that after deploying the size to Azure, the hash algorithm changes... No idea yet how this could be solved.

    Hello,

    No, I gave up on that and used dev storage while running from VS. And yes, I also noticed that behavior. I have no idea why the salt for the hash is changing based on where you run it, but that's the root of the problem.

    Tuesday, July 24, 2012 1:50 PM
  • For all of those with issues...

    Try this and let me know if this does or does not work for you. 

    Problem: DefaultMembershipProvider does not exist in Azure SQL DB or error receiving when registering account about table columns not existing.

    In VS 2012/10 go to "Project" > "Asp.Net Configuration" 

    then go to "Security" and create your security settings...

    I am not sure why you have to do it this way but after doing this my MembershipProvider was in Azure and I was able o register and get everything configured. 

    • Proposed as answer by Bradd Schick Monday, September 24, 2012 5:11 PM
    Monday, September 24, 2012 5:11 PM