.net mvc 电子邮件作为用户名返回错误 - InvalidProviderUserKey
我有一个 .Net MVC 应用程序,我尝试使用电子邮件地址作为用户名。我实现了 本文 中的逻辑,其中用户名被屏蔽为电子邮件。但是,当我尝试拨打
private readonly MembershipProvider _provider;
MembershipCreateStatus status;
_provider.CreateUser(userName, password, email, null, null, true, false, out status);
用户名为“[email protected] 的位置 时",状态始终返回为 InvalidProviderUserKey。如果我使用标准用户名(不带@),它工作正常。我尝试寻找解决方案,但我确实可以在任何地方找到 InvalidProviderUserKey 的解释。
我想知道是否有人以前遇到过这个问题,或者是否能够解释为什么这种情况会返回这个特定状态。预先感谢您的任何帮助。
更新
我使用 Guid.NewGuid 作为 ProviderUserKey 并且它有效。
_provider.CreateUser(userName, password, email,null, null, true, Guid.NewGuid(), out status);
感谢丹尼尔·A·怀特的帮助。您提供的文章链接是我理解它所需要的。
I have a .Net MVC application that I am trying to use an email address as the username. I implemented the logic from this article where the username is masked as the email. However, when I try to call
private readonly MembershipProvider _provider;
MembershipCreateStatus status;
_provider.CreateUser(userName, password, email, null, null, true, false, out status);
where the username is "[email protected]", the status always returns as InvalidProviderUserKey. If i use a standard username (without the @), it works fine. I tried searching for a solution but i can really find an explanation of InvalidProviderUserKey anywhere.
I was wondering if someone has run into this problem before or might be able to offer an explanation of why this scenario would be returning this specific status. Thanks in advance for any help.
UPDATE
I used Guid.NewGuid for the ProviderUserKey and it worked.
_provider.CreateUser(userName, password, email,null, null, true, Guid.NewGuid(), out status);
Thank you Daniel A. White for your help. The article link that you provided was what I needed to understand it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保将某些内容传递给
providerUserKey
,而不仅仅是false
。http://msdn.microsoft.com/en -us/library/system.web.security.membershipprovider.createuser.aspx
Make sure you pass something to
providerUserKey
, not justfalse
.http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.createuser.aspx