20

I started a new internet project with VS2012 and am trying to just restructure my project a bit and I can't seem to keep the SimpleMemberhsipProvider working. Basically, all I've done is move the models objects into a core project along with a couple other items. I've implemented Ninject and am trying to abstract Entity a bit by using a repository pattern to get my data. I really don't feel as though I've changed much with the current project, but for some reason when I start the application now I get:

{"The Role Manager feature has not been enabled."}

The ActionFilter that is supplied by the framework is where the error is thrown when:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "Id", "UserName", autoCreateTables: true);

is called.

Here is some of the stacktrace:

[ProviderException: The Role Manager feature has not been enabled.]
System.Web.Security.Roles.EnsureEnabled() +9561885
System.Web.Security.Roles.get_Provider() +8
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +104
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +100
InoutBoard.Core.Infrastructure.Filters.SimpleMembershipInitializer..ctor() in c:\Users\Kyle\Documents\Visual Studio 2012\Projects\InoutBoard\InoutBoard.Core\Infrastructure\Filters\InitializeSimpleMembershipAttribute.cs:42

[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
InoutBoard.Core.Infrastructure.Filters.SimpleMembershipInitializer..ctor() in c:\Users\Kyle\Documents\Visual Studio 2012\Projects\InoutBoard\InoutBoard.Core\Infrastructure\Filters\InitializeSimpleMembershipAttribute.cs:46

I'm hosting the code on github at the following link https://github.com/keroger2k/InoutBoard

  • take a look at http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx – RickAndMSFT Sep 04 '12 at 02:37
  • @RickAndMSFT I've read that already. It was a great post however it didn't seem to answer my question? –  Sep 04 '12 at 02:48

5 Answers5

24

First way

Check the sphair's answer out (in current thread).

Second way

Add following assemblies to the web.config:

<system.web>
  <compilation debug="true" targetFramework="4.5">
    <assemblies>
      <add assembly="WebMatrix.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add assembly="WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </assemblies>
  </compilation>
</system.web>

Update

The WebMatrix.WebData assembly contains a start up method to initialize Membership/Role providers and enable RoleManager (PreApplicationStartCode.Start). But ASP.NET couldn't find that to run in your case. By adding these two lines of code, we force ASP.NET to search these assemblies for PreApplicationStartMethodAttribute(s).

Community
  • 1
  • 1
m3kh
  • 7,881
  • 2
  • 31
  • 37
10

In case others are getting this error and the above solution doesn't work, like in my case. It said invalid child object when I tried to add in the assemblies markup. I had to specify the roleManager and membership tags as below. Once I did that the update-database worked.

<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear/>
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
      </providers>
    </roleManager>
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <clear/>
        <add name="SimpleMembershipProvider" 
             type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"/>
      </providers>
    </membership> 
Xaxum
  • 3,545
  • 9
  • 46
  • 66
10

I had the exact same error running at my hosting company (WinHost.com - they are excellent BTW).

My solution was to add to the web.config:

<appSettings>
    <add key="enableSimpleMembership" value="true" />
</appSettings>
Chris Patterson
  • 581
  • 3
  • 9
10

Instead of adding the assemblies to the web.config as Mehdi Golchin suggests, an alternative is to change the assembly references on WebMatrix.Data and WebMatrix.WebData to CopyLocal=True.

sphair
  • 1,674
  • 15
  • 29
  • 2
    I agree. I found out the same. If I had continued reading the answers it could have saved me some time :) – Dipen Bhikadya Feb 22 '13 at 02:51
  • I did this on a whim for some other reason (why is this loaded but this isn't? kind of a thing) and was extremely perplexed by it. – vbullinger Jun 03 '13 at 17:36
0

add the key to the Web.Config as the page:

http://devbla.wordpress.com/2013/07/03/corrigindo-o-erro-no-aspnet-the-role-manager-feature-has-not-been-enabled/

[]'s