none
"Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

    Question

  • Hello all,

    I'm trying to get my first-ever Azure app deployed and running.  I have previously succeeded in getting a simple scaffolded app to run locally and online, but now something has changed and, when I try to create and run an app under the local emulator and try to log in or out I get an InvalidOperationException:

    To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider"

    I must have installed some magic that is causing this error.  As far as I know, I have VS 2010 plus the stuff installed by the Web installer (http://go.microsoft.com/fwlink/?LinkID=254269&clcid=0x409) referenced by the tutorial on the Azure website (http://go.microsoft.com/fwlink/?LinkID=254269&clcid=0x409).

    Specifically, here are the reproduceable steps that I've taken to cause this error:

    1. Run VS 2010 as Administrator
    2. New Project
         ASP.NET MVC 4 Web Application
         Name: CodeFirstApp
         Internet Application
    3. Press F5 to run the ASP.NET app
         Verify that Register and Logoff work
    4. Right-click the project in Solution Explorer and select "Add Windows Azure Cloud Service Project"
    5. Right-click CodeFirstApp project in Solution Explorer and select Manage NuGet Packages...
         Click Online
         Search for Universal Providers
         Select and install
           "Microsoft ASP.NET Universal Providers", Id: Microsoft.AspNet.Providers, Version: 1.2
    6. In Web.config, modify the DefaultConnection connection string:
         Replace "Integrated Security=SSPI" with
                 "Integrated Security=True;MultipleActiveResultSets=True"
    7. Press F5 to run the app under the Azure emulator (F5)
         Any attempt to log in or out results in an InvalidOperationException,
         To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider"

    Monday, August 20, 2012 11:22 PM

Answers

All replies

  • Hi,

    Do you enable Webmatrix in you azure application? Because ExtendedMembershipProvider requires WebMatrix.data reference, SimpleMembershipProvider is under the ExtendedMembershipProvider namespace, you can fix this problem with the following article:

    http://www.asp.net/web-pages/tutorials/security/16-adding-security-and-membership

    Note:

    If you see an error that tells you that a property must be an instance of ExtendedMembershipProvider, the site might not be configured to use the ASP.NET Web Pages membership system (SimpleMembership). This can sometimes occur if a hosting provider's server is configured differently than your local server. To fix this, add the following element to the site's Web.config file:

    <appSettings> 
        <add key="enableSimpleMembership" value="true" /> 
    </appSettings>

    Add this element as a child of the <configuration> element and as a peer of the <system.web> element.

    And please also remove all ASP.NET Membership providers in web.config file, such as AspNetMembership, SqlMembership, etc (type = DefaultMembershipProvider). Then i think it will works.

    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

    Tuesday, August 21, 2012 7:46 AM
  • > Do you enable Webmatrix in you azure application?

    Not intentionally.  As I said in the OP, I'm using VS 2010 with whatever magic the Azure WebInstaller gives me.  Let me stress, again, that this procedure -- create an MVC 4 app from the template, add the Azure deployment magic, add the ASP.NET Universal Providers, run the app -- has worked in the past.  But now it's broken.

    > add the following element to the site's Web.config file

    Been there, tried that, doesn't help.  Here's a screen snapshot of my changes:

    > And please also remove all ASP.NET Membership providers...(type = DefaultMembershipProvider)

    Ok, now you're asking me to fiddle with deep dark black magic that was provided by the tooling. I commented out this line in my web.config

    and now, when I run it, I get a TargetInvocationException, with an innerException of "The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588"


    • Edited by Bob.at.SBS Tuesday, August 21, 2012 4:55 PM
    Tuesday, August 21, 2012 4:14 PM
  • Hi,

    Not intentionally.  As I said in the OP, I'm using VS 2010 with whatever magic the Azure WebInstaller gives me.  Let me stress, again, that this procedure -- create an MVC 4 app from the template, add the Azure deployment magic, add the ASP.NET Universal Providers, run the app -- has worked in the past.  But now it's broken.

    As i mentioned above, i just need make sure which authentication you want, Webmatrix or ASP.NET membership provider, if you want Webmatrix, you need to remove ASP.NET membership provider, if you want to use ASP.NET, give up webmatrix class and methods.

    Now your issue become "ASP.NET Simple Membership database could not be initialized", i suggest you looking at these two points:

    • The most common reason is the connection string to SQL Server is not valid. For example, you might not have SQL Server available. This is a frequent cause of failure in Azure. The ASP.NET MVCtemplates by default use SqlExpress when created with Visual Studio 2010 and LocalDB when using Visual Studio 2012. SqlExpress is not installed on Azure and LocalDB does not run on Azure.
    • Multiple DBContext objects on the same database.

    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

    Wednesday, August 22, 2012 2:38 AM
  • Ok, I'm not getting something basic here.  It used to work.  Now it doesn't.  I'm just running the code created by the ASP.NET MVC 4 template, just like the tutorials tell you to do.  In the tutorials, the ONLY modification needed to make it run under Azure is to get the correct "universal provider" and adding "MultiplActiveResultSets=true" to the connection string.  I've done that in the past and it worked.  Why, now, must I muck around with membership provider claptrap?
    Wednesday, August 22, 2012 2:50 AM
  • After much experimentation, I've figured out what I changed to cause it to stop working.  I would love an explanation of the underlying magic that broke on me.

    The tutorial (referenced in the OP) instructs me to create an MVC 3 project.  When I do that, everything works "out of the box".  I create the project, add an Azure Deployment project, add the Microsoft.AspNet.Providers NuGet package, add the MultipleActiveResultSets magic to the connection string, and, it runs just fine under the Azure emulator.

    When I do the exact same set of steps with an MVC 4 project, it fails with the "ExtendedMembershipProvider" error.

    I read somewhere that the membership code provided by the MVC 4 project template is quite different than that provided by the MVC 3 template.  But the blurb I stumbled across only talked about the differences in the table schema.  Obviously, there is some other fundamental difference between the two templates that causes this error.  That difference doesn't appear to be in the web.config file - all of the membership claptrap in that file appears to be identical between MVC 3 and MVC 4.

    So... can someone please point me at an explanation of how MVC 4 does membership that's different from the way MVC 3 does it, and what I need to do to get a simple MVC 4 app to run under Azure?

    Thanks!

    Bob

    Wednesday, August 22, 2012 10:26 PM
  • Read this to get basic idea about SimpleMembershipProvider:

    http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx

    It might help you get started...

    Thursday, August 23, 2012 11:14 AM
  • MVC4 uses simplemembership which was released with ASP.NET webpages.More info here (http://www.asp.net/web-pages/tutorials/security/16-adding-security-and-membership)

    Simplemembership extends the asp.net membership system but has a different schema as compared to asp.net providers

    MVC3 used the asp.net sql membership providers

    To get your app working in azure do the following

    - create a new azure cloud service and select mvc4 project template

    or

    when you add the azure deployment project uninstall the universal providers(skip this step)

    5. Right-click CodeFirstApp project in Solution Explorer and select Manage NuGet Packages...
         Click Online
         Search for Universal Providers
         Select and install
           "Microsoft ASP.NET Universal Providers", Id: Microsoft.AspNet.Providers, Version: 1.2

    • Marked as answer by Bob.at.SBS Friday, August 24, 2012 12:59 AM
    Thursday, August 23, 2012 5:06 PM
  • Thanks.  So, to recap (in case someone else comes along looking for a concise answer):

    MVC 3 uses the ASP.NET SQL membership providers:

    http://msdn.microsoft.com/en-us/library/aa478948.asp

    To get an MVC 3 app to run under Azure, you must install the Universal Providers (Microsoft.AspNet.Providers) NuGet package.

    MVC 4 uses the new and improved SimpleMembership extension to the ASP.NET membership framework:

      http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx
      http://www.asp.net/web-pages/tutorials/security/16-adding-security-and-membership

    To get an MVC 4 app to run under Azure, just add an Azure Deployment project.  No need for the Universal Providers package -- in fact, installing that package results in the arcane error that started this whole thread.

    • Marked as answer by Bob.at.SBS Friday, August 24, 2012 1:16 AM
    Friday, August 24, 2012 1:16 AM