开发者

FormsAuthentication.Authenticate fails to authenticate

I currently have an odd problem with ASP.Net authentication. Consider the two following lines:

开发者_StackOverflow中文版
MembershipCreateStatus ct = new MembershipCreateStatus();
Membership.CreateUser("admin", "mypassword", "test@gmail.com", "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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜