FormsAuthentication.Authenticate 身份验证失败
我目前在 ASP.Net 身份验证方面遇到一个奇怪的问题。 考虑以下两行:
MembershipCreateStatus ct = new MembershipCreateStatus();
Membership.CreateUser("admin", "mypassword", "[email protected]", "1", "1", true, out ct);
这确实在我的数据库中注册了我的用户。我已经验证了这一点。 但是,当我立即运行此命令时:
FormsAuthentication.Authenticate("admin", "mypassword");
身份验证失败。奇怪的是,我知道该用户确实存在于数据库中,并且如果我运行
MembershipUserCollection uc = Membership.FindUsersByName("admin");
并且 uc 确实保留了我的管理员用户以及所有正确的信息,则可以进一步确认这一点。 任何人有关于为什么 Authenticate 会返回 false 的任何想法或提示吗?
I currently have an odd problem with ASP.Net authentication.
Consider the two following lines:
MembershipCreateStatus ct = new MembershipCreateStatus();
Membership.CreateUser("admin", "mypassword", "[email protected]", "1", "1", true, out ct);
This does register my user in my database. I have verified this.
However, when I run this immediately after:
FormsAuthentication.Authenticate("admin", "mypassword");
The authentication fails. The weird thing is I know for a fact that the user does exist in the db, and that is further confirmed if i run
MembershipUserCollection uc = Membership.FindUsersByName("admin");
and uc does hold my admin user withe all the proper info.
Any ideas or hints from anyone as to why Authenticate would return false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不久前我学到了一些东西 - 在 MSDN 上查找信息时总是阅读备注部分。您会惊讶地发现,它通常包含最重要的信息,如果不加以覆盖,可能会让您陷入困境几个小时,有时甚至几天。请参阅此处了解该方法的部分。然后调用 ValidateUser 进行授权,即与验证不同。请查看此处。
I learned something a little while ago - when looking up info on MSDN always read the remarks section. You'll be surprised that it usually contains the most vital info which, if not covered, can trap you for hours sometimes days. See that section for that method here. Then call ValidateUser to authorze which is different from authenticate. Have a look here.