Take the 2-minute tour ×

My code behind

protected void LogonForm_Authenticate(object sender, AuthenticateEventArgs e)
    bool auth = false;

    if (FormsAuthentication.Authenticate(LogonForm.UserName, LogonForm.Password))
        auth = true;

    e.Authenticated = auth;


It results in false. When I don't specify an OnAuthenticate event the user is validated it works as expected. What gives?

I simply want to invoke the default OnAuthenticate code and then add an additional check on the end of it. I am using LDAP to authenticate in both scenarios.

share|improve this question
Can you please mention on what kind of membership provider are you relying on for authentication? Is some custom membership provider that inherits the MembershipProvider abstract class? (The type of the provider set set from <membership> <providers> in web.config) –  andrei m Nov 19 '10 at 22:01

2 Answers 2

up vote 2 down vote accepted

As is mentioned in the documentation on MSDN, the FormsAuthentication.Authenticate method should be used in case you have the credentials stored in the Web.config file like this:

<authentication mode="Forms">
    <forms loginUrl="login.aspx">
        <credentials passwordFormat="Clear">
            <user name="user1" password="password1" />
            <user name="user2" password="password2" />

But if you are validating the credentials against a membership provider that inherits from the MembershipProvider abstract class like SqlMembershipProvider, ActiveDirectoryMembershipProvider or other custom providers you should use the Membership.ValidateUser method instead.

I think that replacing

if (FormsAuthentication.Authenticate(LogonForm.UserName, LogonForm.Password))


if (Membership.ValidateUser(LoginUser.UserName, LoginUser.Password))

will solve your problem.

share|improve this answer

Can you provide more code? Authenticate only AUTHENTICATE's a user, it doesnt set a cookie, etc. Use this method to determine if a username\password is valid (aka if it returns True)

Try this instead to set the cookie:

Dim boolVal as Boolean = FormsAuthentication.Authenticate(LogonForm.UserName, LogonForm.Password)
If boolVal Then
End If
share|improve this answer
I updated my post. I understand that I need to set the cookie too, but for whatever reason FormsAuthentication.Authenticate is resulting in false when I am passing logon box username/password. I think that the original Authenticate is doing more before this call and somehow resulting in true. –  ryan Nov 19 '10 at 18:19

Your Answer


