问题描述
我使用的是内置的ASP.net MVC4模板SimpleMembership并希望创建一个管理员面板来重置用户群密码和类似的操作。
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.
我使用SecurityGuard.MVC4的NuGet作为出发点和我得到的大多数操作NotSupportedException异常。 SecurityGuard使用控制器的成员属性来调用的方法,如关于SimpleMembershipProvider GetAllUsers(),的getUser()和ResetPassword(),它们都掷NotSupportedException异常。从技术文档似乎这是由设计:
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
请注意:如果SimpleMembershipProvider类已使用初始化
一个打电话到WebSecurity.InitializeDatabaseConnection()方法,该
方法不支持,将引发NotSupportedException
例外。然而,如果WebSecurity.InitializeDatabaseConnection()
方法还没有被调用,如果你已经配置您的网站
使用标准的ASP.NET成员资格提供程序,这种方法传递
通过对标准的成员提供。
我在想什么?看来我需要使用WebSecurity标准的东西像WebSecurity.CreateUser(),并直接使用供应商之间进行选择?
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?
推荐答案
SimpleMembership
是故意设计成..嗯,简单。 WebSecurity
使用 SimpleMembership
,并使用 ExtendedMembershipProvider 类code> SimpleMembership 源自
SimpleMembership
is deliberately designed to be.. well, Simple. WebSecurity
uses SimpleMembership
, and uses the ExtendedMembershipProvider
class that SimpleMembership
is derived from.
实质上,SimpleMembership不实现不在WebSecurity present任何功能,并且GetAllUsers是其中的一个。是的,这是由设计。
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.
- 您可以简单地做自己的查询来获取所有用户。
- 您可以创建SimpleMembership得出你自己的会员提供者和执行这些功能
- 您可以回去的SqlMembershipProvider(或通用提供商)(但避开WebSecurity)
这篇关于当初始化SimpleMembershipProvider在MVC4引发NotSupportedException上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!