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

2

5 Answers 5

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).

6
  • Could you elaborate more on why this is required?
    – user342706
    Sep 5, 2012 at 2:37
  • Sorry for the lack of explanation, added.
    – m3kh
    Sep 5, 2012 at 5:20
  • See also my suggested answer below regarding setting the references to local copy.
    – sphair
    Jan 3, 2013 at 22:43
  • Howcome the default Internet Application doesn't have to use this? Where does that code call this? Feb 3, 2013 at 13:15
  • 3
    Default internet application sets WebMatrix.Data and WebMatrix.WebData references as CopyLocal = True. Feb 22, 2013 at 2:49
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> 
0
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>
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.

2
  • 2
    I agree. I found out the same. If I had continued reading the answers it could have saved me some time :) Feb 22, 2013 at 2: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 3, 2013 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.