SimpleMembershipProvider not working
Asked Answered
S

5

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

Salisbury answered 3/9, 2012 at 22:33 Comment(2)
take a look at weblogs.asp.net/jgalloway/archive/2012/08/29/…Dorran
@Dorran I've read that already. It was a great post however it didn't seem to answer my question?Salisbury
G
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).

Gandy answered 4/9, 2012 at 7:53 Comment(6)
Could you elaborate more on why this is required?Salisbury
Sorry for the lack of explanation, added.Gandy
See also my suggested answer below regarding setting the references to local copy.Bega
Howcome the default Internet Application doesn't have to use this? Where does that code call this?Navigable
Default internet application sets WebMatrix.Data and WebMatrix.WebData references as CopyLocal = True.Vidrine
I just want to note that this also solved my problem when trying to implement this in a WCF backend.Hamite
P
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> 
Phonics answered 19/10, 2012 at 19:16 Comment(0)
C
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>
Considered answered 30/10, 2012 at 16:26 Comment(0)
B
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.

Bega answered 3/1, 2013 at 22:43 Comment(2)
I agree. I found out the same. If I had continued reading the answers it could have saved me some time :)Vidrine
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.Posterior
H
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

Hogen answered 3/7, 2013 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.