Question

I am using the built-in SimpleMembership of the ASP.net MVC4 template and want to create an admin panel to reset passwords and similar operations on the user base.

I am using SecurityGuard.MVC4 nuget as starting point and am getting NotSupportedException on most actions. SecurityGuard uses the Membership property of the controller to call methods such as GetAllUsers(), GetUser() and ResetPassword() on SimpleMembershipProvider and they all throw NotSupportedException. From documentation it seems that this is by design:

SimpleMembershipProvider.GetAllUsers

Note: If the SimpleMembershipProvider class has been initialized using a call to the WebSecurity.InitializeDatabaseConnection() method, this method is not supported and will throw a NotSupportedException exception. However, if the WebSecurity.InitializeDatabaseConnection() method has not been called, and if you have configured your site to use the standard ASP.NET membership provider, this method is passed through to the standard membership provider.

What am I missing? It seems I need to choose between using WebSecurity for standard stuff like WebSecurity.CreateUser() and to use the provider directly?

I can work around this, but I am primarily confused on why I can't get both?

Was it helpful?

Solution

SimpleMembership is deliberately designed to be.. well, Simple. WebSecurity uses SimpleMembership, and uses the ExtendedMembershipProvider class that SimpleMembership is derived from.

Essentially, SimpleMembership does not implement any functions that are not present in WebSecurity, and GetAllUsers is one of those. Yes, this is by design.

You have several options. All of them are workarounds.

  1. You can simply do your own query to get all users.
  2. You can create your own Membership provider derived from SimpleMembership and implement those functions
  3. You can go back to the SqlMembershipProvider (or Universal Providers) (but eschew WebSecurity)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top