The simplest process is as follows:
1. Create a class named CustomMemberShipProvider, inherit from MembershipProvider, and override the ValidateUser method:
Public class CustomMemberShipProvider: MembershipProvider
{
/// <Summary>
/// Verify the user
/// </Summary>
/// <Param name = "username"> </param>
/// <Param name = "password"> </param>
/// <Returns> </returns>
Public override bool ValidateUser (string username, string password)
{
// Query the user
Return 1 = new xxxEntities (). Table_User
. Count (x => x. UserId = username & x. Password = password );
}
Public override string ApplicationName
{
Get
{
Return "xxx ";
}
Set
{
Throw new NotImplementedException ();
}
}
// The remaining code is not modified.
}
2. Modify the web. config file and add a MembershipProvide. The settings are as follows:
<membership defaultProvider="CustomMembershipProvide">
<providers >
<clear />
<!--<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />-->
<add name="CustomMembershipProvide" type="xxx.Models.CustomMemberShipProvider" />
</providers>
</membership>
<profile>
3. if you add [Authorize] before the Action in Asp.net MVC, You can implement anonymous identity authentication.