指定的会员资格提供商名称无效。参数名称:providerName
- .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该名称不应该与 web.config 中指定的名称相同吗?
即 OnyxMembershipProvider
Shouldn't the name be the same as that specified in the web.config?
i.e. OnyxMembershipProvider
您可能需要考虑嘲笑会员资格提供者。您的单元测试应该测试您的代码,而不是 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?