2

I recently updated an MVC 4 site using simple membership to MVC 5. I then have a line in a controller that uses the membership provider:

SimpleMembershipProvider provider = new SimpleMembershipProvider();
if (provider.GetUserId(User.Identity.Name) == id)

However on that controller I get the message:

You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class. This call should be placed in an _AppStart.cshtml file in the root of your site.

So I googled it and applied the stackoverflow suggestion in this link to global.asax. That didnt work so I applied it to the AuthConfig in App_start folder. That also doesnt work.

Has anyone found how to get this working in MVC 5? Your help is much appreciated.

Community
  • 1
  • 1
dalcam
  • 1,027
  • 11
  • 28

1 Answers1

1

Sorry what a bad oversight! I should be using the WebSecurity class, not the simpleMembershipProvider class. So i simply updated both the lines in the controller above to:

if (WebSecurity.CurrentUserId == id)

And the problem is gone.

dalcam
  • 1,027
  • 11
  • 28