指定的会员资格提供商名称无效。参数名称:providerName

发布于 2024-09-15 11:01:54 字数 1749 浏览 15 评论 0原文

  • .Net4.0
  • MVC 2
  • NHibernate
  • NUnit

我正在尝试测试用户创建。根据我的测试,我调用以下内容:

MembershipCreateStatus status;
// _session is my current NHibernate session.
var mmp = new MyMembershipProvider(_session);
mmp.CreateUser(username, password, "[email protected]", "", "", true, Guid.NewGuid(), out status);

CreateUser 方法中,它达到了以下目的:

var user = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, passwordAnswer, isApproved, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

...在抛出此异常之前:

The membership provider name specified is invalid.
Parameter name: providerName

我将我的名称设置为 MyMembershipProvider ,在 Web.config 中我有这个:

<add name="OnyxMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
  enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
  maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
  applicationName="/" />

而且,我的连接字符串:

<add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />

现在,我猜问题是我的测试正在创建一个 SQLite DB,而 web.Config 正在尝试访问我的 SqlServer DB,但我不知道如何继续。

  • .Net4.0
  • MVC 2
  • NHibernate
  • NUnit

I'm trying to test user creation. From my test, I'm calling the following:

MembershipCreateStatus status;
// _session is my current NHibernate session.
var mmp = new MyMembershipProvider(_session);
mmp.CreateUser(username, password, "[email protected]", "", "", true, Guid.NewGuid(), out status);

In the CreateUser method, it gets this far:

var user = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, passwordAnswer, isApproved, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);

... before throwing this exception:

The membership provider name specified is invalid.
Parameter name: providerName

I have my Name set to MyMembershipProvider, and in the Web.config I have this:

<add name="OnyxMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
  enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
  maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
  applicationName="/" />

And also, my connection string:

<add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />

Now, I'm guessing the the problem is that my tests are creating a SQLite DB, and the web.Config is trying to hit my SqlServer DB, but I'm not sure how to proceed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尾戒 2024-09-22 11:01:55

该名称不应该与 web.config 中指定的名称相同吗?

即 OnyxMembershipProvider

Shouldn't the name be the same as that specified in the web.config?

i.e. OnyxMembershipProvider

铜锣湾横着走 2024-09-22 11:01:55

您可能需要考虑嘲笑会员资格提供者。您的单元测试应该测试您的代码,而不是 Microsoft 的代码。

以下是有关使用 Moq 模拟会员提供程序的一些信息:

什么这次我在起订量方面做错了吗?

You might want to consider mocking the membership provider. Your unit tests should be testing your code, not Microsoft's.

Here's some information on using Moq to mock out the membership provider:

What am I doing wrong this time with Moq?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文