当初始化SimpleMembershipProvider在MVC4引发NotSupportedException上的方法 [英] SimpleMembershipProvider in MVC4 throws NotSupportedException on methods when initialized

查看:202
本文介绍了当初始化SimpleMembershipProvider在MVC4引发NotSupportedException上的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是内置的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:

<一个href=\"http://msdn.microsoft.com/en-us/library/webmatrix.webdata.simplemembershipprovider.getallusers%28v=vs.111%29.aspx\"相对=nofollow> SimpleMembershipProvider.GetAllUsers

请注意:如果SimpleMembershipProvider类已使用初始化
  一个打电话到WebSecurity.InitializeDatabaseConnection()方法,该
  方法不支持,将引发NotSupportedException
  例外。然而,如果WebSecurity.InitializeDatabaseConnection()
  方法还没有被调用,如果你已经配置您的网站
  使用标准的ASP.NET成员资格提供程序,这种方法传递
  通过对标准的成员提供。

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.

我在想什么?看来我需要使用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.


  1. 您可以简单地做自己的查询来获取所有用户。

  2. 您可以创建SimpleMembership得出你自己的会员提供者和执行这些功能

  3. 您可以回去的SqlMembershipProvider(或通用提供商)(但避开WebSecurity)

这篇关于当初始化SimpleMembershipProvider在MVC4引发NotSupportedException上的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆