Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use two membership provider in my application, when user key in the username and password, it should check username in first membership provider, if not in first provider, then only search username in second membership provider. But the problem is, everytime it search on second membership provider, the profile and role provider still is first provider. What I do wrong in my code?

What I have tried:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
    MembershipProvider ProviderName = Membership.Providers["MySqlMembershipProvider2"];


    if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
    {
        e.Authenticated = true;
        Login1.DestinationPageUrl = "~/Start.aspx";
    }
    else
    {
        if (Membership.Providers["MySqlMembershipProvider2"].ValidateUser(Login1.UserName, Login1.Password) == true)
        {

            RoleProvider RoleName= Roles.Providers["MySqlRoleProvider2"];
            ProviderName.GetUser(Login1.UserName,true);
            e.Authenticated = true;
            Login1.DestinationPageUrl = "~/CL/CLLogin.aspx";
        }
        else
        {
            e.Authenticated = false;
        }
    }
}

web.config:
<roleManager defaultProvider="MySQLRoleProvider" enabled="true">
  <providers>
    <clear/>
    <add name="MySQLRoleProvider" connectionStringName="MySQLMembershipConnection" applicationName="/" type="MySql.Web.Security.MySQLRoleProvider" autogenerateschema="true"/>
    <add name="MySQLRoleProvider2" connectionStringName="MySQLMembershipConnection2" applicationName="/" type="MySql.Web.Security.MySQLRoleProvider" autogenerateschema="true"/>
  </providers>
</roleManager>
<anonymousIdentification enabled="true"/>
<membership defaultProvider="MySQLMembershipProvider">
  <providers>
    <clear/>
    <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider" connectionStringName="MySQLMembershipConnection" autogenerateschema="true" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"/>
    <add name="MySQLMembershipProvider2" type="MySql.Web.Security.MySQLMembershipProvider" connectionStringName="MySQLMembershipConnection2" autogenerateschema="true" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"/>
  </providers>
</membership>
<profile defaultProvider="MySQLProfileProvider">
  <providers>
    <clear/>
    <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySqlProfileProvider" applicationName="/" connectionStringName="MySQLMembershipConnection" autogenerateschema="true"/>
    <add name="MySQLProfileProvider2" type="MySql.Web.Profile.MySqlProfileProvider" applicationName="/" connectionStringName="MySQLMembershipConnection2" autogenerateschema="true"/>
  </providers>
  <properties>
    <add name="FullName" provider="MySQLProfileProvider"/>
    <add name="FName" provider="MySQLProfileProvider"/>
    <add name="ClassName" provider="MySQLProfileProvider2"/>
    <add name="Area" provider="MySQLProfileProvider2"/>
  </properties>
</profile>
<sessionState>
  <providers>
    <add name="MySqlSessionStateStore" type="MySql.Web.SessionState.MySqlSessionStateStore,MySql.Web"/>
    <add name="MySqlSessionStateStore2" type="MySql.Web.SessionState.MySqlSessionStateStore,MySql.Web"/>
  </providers>
</sessionState>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900