Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormsAuthentication.Authenticate fails to authenticate

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?

like image 218
snwr Avatar asked Feb 08 '11 07:02

snwr


People also ask

How do I enable form authentication in IIS?

To configure forms authentication by using the UIOpen IIS Manager and navigate to the level you want to manage. In Features View, double-click Authentication. On the Authentication page, select Forms Authentication. In the Actions pane, click Enable to use Forms authentication with the default settings.

What does FormsAuthentication SetAuthCookie do?

The SetAuthCookie method adds a forms-authentication ticket to either the cookies collection, or to the URL if CookiesSupported is false . The forms-authentication ticket supplies forms-authentication information to the next request made by the browser.


1 Answers

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.

like image 75
walt jimi Avatar answered Sep 22 '22 12:09

walt jimi