将电子邮件地址设置为 ASP.NET 会员提供商中的用户名
我想在会员 api 中使用电子邮件地址作为用户名,而不是接受用户名。 我希望用户可以使用电子邮件地址注册我的网站,并且可以使用电子邮件 ID 和密码而不是用户名和密码登录。
I want to use email address as username in membership api instead of accepting a username.
I want that a user can signup to my site using email address and he can login using email id and password instead username and password.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我们所做的,因此它是可重用的,我们可以在 web.config 中注册它。如果你仔细想想,这就是最重要的地方。只要您的验证和前端向最终用户表明他们的用户名应该是电子邮件,并且您进行了正确的验证...从那里它会正常调用支持您的任何会员提供商。快捷版本的新方法,并将原始版本隐藏/更改在我们的外观后面。
This is what we did, so its reusable and we can reg it in the web.config. If you think about it, this is where it counts. as long as your validation and frontend indicate to the enduser that their username should be email, and you do proper validation... from there its normal calls to whatever membership provider is backing you. New method for the shortcut version, and hiding/altering the original behind our facade.
正如本线程中所描述的,这一切都是可能的,但需要注意一件事:在数据库中,用户名的长度为 50 个字符(表 Users),而电子邮件(表 Memberships)的长度为 256 个字符。事实上,这意味着更短的电子邮件地址。 :)
This is all possible as described in this thread already, but there's one thing to be aware of: in the database the username is 50 chars (table Users) long while the email (table Memberships) is 256 chars long. In fact that means shorter email addresses. :)
只需强制用户名=用户电子邮件即可。
为此,只需在用户创建表单上放置一个正则表达式验证器,以仅允许正确的电子邮件作为用户名。
根据用户的电子邮件重命名现有的用户名。
Just force user name = user email.
To do this just put a RegEx validator on user creation form to allow only proper email as user name.
Rename already existing user names according to users' email.