0

Hoping you may be able to help with a peculiar issue I'm facing with my SimpleMembershipProvider.

I have an MVC4 application that uses the SimpleMembership feature to store user and role information. This all works perfectly from the front end MVC4 application.

We also have a web service which will call the same SimpleMembershipProvider to validate the user credentials from a mobile app using the standard ValidateUser() method.

However, before I get to my ValidateUser() method I need to initialise my WebSecurity object using the WebSecurity.InitializeDatabaseConnection method. This is causing the below error:

"The Role Manager feature has not been enabled."

I'm initialising the WebSecurity object within the services startup, using the same code pulled from my Portal:

    if (!WebSecurity.Initialized)
    {
    WebSecurity.InitializeDatabaseConnection("PortalContext", "UserProfile", "UserId", "UserName", autoCreateTables: true);
    }

I've checked that my web.config of my web service contains the appSettings key

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

I've also included the rolemanager and membership details within my system.web section of my web.config.

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

I'm now completely at a loss and have spent all morning googling for a possible solution.

Can anyone think of a reason why this might be occurring?

Martin Crawley
  • 477
  • 1
  • 7
  • 16
  • What makes you think initialization is causing this error? Usually when initialization has not occurred you will see a specific error about initialization. What does your connection string look like for PortalContext? Does it match what is in your web application? I get the impression from you comments that your web service is a separate application from the web application. Why not just add a Web API in your web application to provide this service.? – Kevin Junghans Aug 21 '13 at 18:41
  • Hi Kevin, thanks for the response. It's definately the call to InitializeDatabaseConnection() that's failing - Whatever this method entails, it's not allowing me to initialise the WebSecurity. All the set up looks fine to me though, hence why I'm so puzzled! – Martin Crawley Aug 21 '13 at 19:28
  • My connection string is a straight copy from the MVC4 web app, so the name matches PortalContext etc. It's an ordinary SQL connection, although I don't have it to hand right now to post. And yes, you're correct that the web service is a separate application from the MVC4 web app but they both have a reference to another project which holds my DB context. The reason we chose to host a separate Web Service was because we were also creating a mobile app, which would communicate with BizTalk which would then in-turn communicate with the Web Service. – Martin Crawley Aug 21 '13 at 19:38
  • Take a look at this QA [http://stackoverflow.com/questions/12254701/simplemembershipprovider-not-working] and see if it helps in your situation. – Kevin Junghans Aug 21 '13 at 19:59
  • Hi Kevin, thanks for this but I've already reviewed all the solutions on this QA to no avail. – Martin Crawley Aug 22 '13 at 07:03

1 Answers1

0

If you have multiple projects in the same solution and are using migrations, make the as the startup project the one containing the migrations (in Solution Explorer, Right click Project name > "Set as startup project") before running database-update.

dunwan
  • 1,577
  • 2
  • 16
  • 14