1 > Create your own Membership Provider Class and inherit it from base MembershipProvider class. If you are using VB.NET the needed methods are added automatically. If you are using C# just right click the MembershipProvider class and add the properties and methods . Don't forget to import System.Configuration.Provider namespace.
The IDE will generate all the methods and properties and you don't have to implement all of them.
The only method that you need to implement is ValidateUser(string username, string password)
You can leave all the other methods throw an exception unless you explicitly want the facility provided by non implemented method.
public class MyCustomMemershipProvider : MembershipProvider { public int TryLogin(string id, string pass) // My own login method { int roleId = 0; DatabaseUtilityHelper databaseHelper = new DatabaseUtilityHelper(); SqlConnection con = databaseHelper.GetBBCDatabaseConnection(); SqlParameter[] agentParams = new SqlParameter[] { new SqlParameter("@UserId",id), new SqlParameter("@Password",pass)}; con.Open(); SqlDataReader reader = DatabaseUtility.ExecuteReader(con, "login_user", CommandType.StoredProcedure, agentParams); if (reader.Read()) { roleId = Int32.Parse(reader.GetSqlValue(1).ToString()); } else { roleId = 0; } con.Close(); return roleId; } public override string ApplicationName { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } } ..... ..... // Generated Code .... .... public override bool ValidateUser(string username, string password) { int result = TryLogin(username, password); if (result > 0) { return true; } else { return false; } }
2 > Add CustomeMemberShip Provider to your web.config
<membership defaultProvider="MyCustomMemershipProvider"> <providers> <clear/> <add name="MyCustomMemershipProvider" type="BBCApplication.BusinessLogic.MyCustomMemershipProvider"/> </providers> </membership>
3.> Add Membership Provider for your login control on Login.aspx page.
In the Properties window of the Login control set MembershipProvider to your MyCustomeMembershipProvider class.
That is it.
Off you go to your own login logic with custom membership provider.