ASP.NET MVC 会员储备
我希望能够阻止用户使用特定用户名(例如“Admin”、“Administrator”等)进行注册。MVC MembershipService 是否有办法执行此操作,或者我必须实现自己的方法来在每次用户注册时进行检查?
谢谢 绕口令
I want to be able to prevent users from registering using specific usernames such as "Admin", "Administrator" etc. Does the MVC MembershipService have a way of doing this or will I have to implement my own method to check each time a user registers?
Thanks
TheLorax
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
罗伯特的回答虽然不优雅,但相当权宜之计。 一种更优雅的方法是将一些逻辑放入 AccountController 的 Register 方法中,以根据“黑名单”检查名称,然后如果名称被列入黑名单,则添加适当的 ModelErrors。 您还可以折叠其他逻辑检查 - 例如验证用户名不是符号的集合,不是亵渎的等等。
有人可以提出这样的论点:这实际上应该在 MembershipProvider 而不是控制器中实现,并且一个会很准确,但这超出了这个答案的范围。
Robert's answer is pretty expedient if inelegant. A more elegant way would be to put some logic into the AccountController's Register method to check names against a "blacklist" then add appropriate ModelErrors if the name is blacklisted. You could also fold in other logical checks--such as verifying the user name isn't a collection of symbols, isn't profane, etc.
One could make an argument that this should really be implemented in the MembershipProvider rather than a controller and one would be pretty spot on but that is beyond the scope of this answer.
如果只有少数几个名字,请自行注册。 这将阻止其他人注册它们。
If it's only a handful of names, register them yourself. That will prevent anyone else from registering them.