ASP.NET FormsAuthentication does not use default MembershipProvider
I have created a BasicMembershipProvider class that inherits from MembershipProvider, when implemented, the ValidateUser does not get called. This is my setup:
web.config
<membership defaultProvider="BasicMembershipProvider">
<providers>
<clear/>
<add name="BasicMembershipProvider" type="MyMVCProject.Providers.BasicMember开发者_如何学编程shipProvider"/>
</providers>
</membership>
BasicMembershipProvider.cs
public class BasicMembershipProvider : MembershipProvider
{
//THIS FUNCTION NEVER GETS CALLED
public override bool ValidateUser(string email, string password)
{
//Do custom checks.
}
}
Controller
FormsAuthentication.Authenticate(model.Email, model.Password)
Is this the way to go about overriding the MembershipProvider with my own membership logic? If so, why doesn't the overidden function ValidateUser
gets called whenever I call FormsAuthentication.Authenticate()
?
AFAIK the FormsAuthentication.Authenticate
does not use Membership.Validate
method. You have to call the Membership.Validate
manually.
From MSDN
The Authenticate method verifies user credentials that are stored in the credentials section of the application configuration file. Alternatively, you can use ASP.NET membership to store user credentials and call the ValidateUser to verify the credentials.
精彩评论