多个会员提供者的 Membership.CreateUser
我在一个网站上处理多个会员提供商时遇到问题。
我有一个注册页面,用于创建用户并将其添加到 AD 域。在我拥有一个会员提供商之前,我在调用的页面上
Membership.CreateUser(txtUsername.Text, txtPassword.Text)
根据页面上的用户输入创建了用户名。
不过,我在 web.config 中添加了另一个会员提供程序,以便可以使用登录页面从另一个 AD 登录。现在,我的注册页面将无法工作,因为(我假设)有两个会员提供商?
我该如何解决这个问题?当我调用 Membership.CreateUser 时,如何指定使用哪个提供程序?
谢谢。
编辑:
正确的方法如下所述:
MembershipCreateStatus newStatus = new MembershipCreateStatus();
Membership.Providers["ProviderName"].CreateUser(txtUserName.Text, txtPassword.Text, null, null, null, true,null, out newStatus);
谢谢!
I am having trouble with handling multiple Membership Providers on one site.
I have a registration page that creates user and adds them to an AD domain. Before I had one membership provider and on the page I called
Membership.CreateUser(txtUsername.Text, txtPassword.Text)
which created the username based on the user inputs on the page.
However, I added another membership provider to the web.config so that the log in page can be used to log in from another AD. Now, my registration page will not work because (I assume) there is two membership providers?
How can I fix this? How do I specify which provider to use when I call Membership.CreateUser?
Thanks.
Edit:
The correct way to do this, as mentioned below is :
MembershipCreateStatus newStatus = new MembershipCreateStatus();
Membership.Providers["ProviderName"].CreateUser(txtUserName.Text, txtPassword.Text, null, null, null, true,null, out newStatus);
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,在这种情况下只有一个 CreateUser 方法,但您可以传递 null 或其他不需要的参数。
编辑:
这是使用显式提供程序调用该方法的唯一方法。我还没有尝试在 AD 中创建用户,所以不确定是否可以解决该错误,但这是另一种方法。
将 CreateUser 的提供程序设置为默认提供程序,以便您可以返回到旧的 CreateUser 调用。但现在您调整登录调用以使用另一个提供商,例如
Note that there is only one CreateUser method in this case but you can pass null of other parameters that are not needed.
Edit:
That is the only way to call that method with explicit provider. I haven't tried creating user in AD so not sure about resolving that error but here is another way.
Make the provider for CreateUser as your defaultprovider and so you can go back to the old CreateUser call. But now you adjust your login call to use another provider e.g.
< 上有一个 Providers 属性包含 会员资格 href="http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovidercollection.aspx" rel="nofollow">成员资格提供商的集合。您应该能够从那里辨别出要使用哪个提供商。
There is a Providers property on Membership that contains a collection of the membership providers. You should be able to discern which provider to use from there.