1

I have created a new MVC 4 project in VS2012 and now experiencing problems trying to use a custom membership provider I have created, which inherits from MembershipProvider.

The AccountController.Login method throws this exception:

To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

Disabling enableSimpleMembership and autoFormsAuthentication (as recommended at asp.net 4.5 custom membership provider configuration throws strange exception) makes no difference.

Removing the WebMatrix.WebData.dll, causes AccountController to not compile as it references WebMatrix.WebData.WebSecurity

These are the steps I took:

  • In VS 2012 create a new APS.NET MVC 4 project (.net 4.0)

  • Add a new class called CustomMembershipProvider that implements MembershipProvider

  • In the web.config set enableSimpleMembership = false and autoFormsAuthentication = false in appSettings and add the membership provider in system.web

  • Start the website in debug and click "Log in" on the page

  • Enter any old text for username and password

I get the exception:

To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider"

Any ideas?

Community
  • 1
  • 1
Langers
  • 141
  • 1
  • 9

1 Answers1

2

I followed your steps, with VS.Net 2010 that is, and was able to reproduce the exception.

This can be solved by implementing ExtendedMembershipProvider rather than MembershipProvider, as the exception indicates.

ExtendedMembershipProvider lives in assembly WebMatrix.WebData.dll and namespace WebMatrix.WebData. It defines many more abstract methods and properties than MembershipProvider, like GeneratePasswordResetToken and GetLastPasswordFailureDate, all of which you'll need to implement.

For a start, you could simply use Implement Abstract Class from the context menu on : ExtendedMembershipProvider and see if it works for you, like it did for me.

If you started with the steps to reproduce, replacing the body of ValidateUser by return true; will allow you to login successfully with any username and password.

R. Schreurs
  • 8,587
  • 5
  • 43
  • 62