Skip to content Skip to sidebar Skip to footer

How To Configure Member Ship With A Database Other Than Aspnetdb

I created one database and tables to store the user login values and credentials. asp.net is providing aspnet_regsql tool to create a database for the membership related activities

Solution 1:

You need to create a membership provider to connect to your custom tables for authentication. MSDN has some documentation on the subject. You can also view a video on the subject at ASP.NET. Here are the links.

The main method for validation is going to be the ValidateUser method, you will override this method to provide authentication.

publicsealedclassCustomMembershipProvider : MembershipProvider
{
    // implement other methodspublicoverrideboolValidateUser(string username, string password)
    {
        try
        {
            var user = // GET USER OBJECT HEREif (user != null)
            {
                string name =  // set username// Set your forms authentication ticket
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.ID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), false, name, FormsAuthentication.FormsCookiePath);

                HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                HttpContext.Current.Response.Cookies.Add(authCookie); 
                returntrue;                    
            }
        }
        catch
        {
        }

        returnfalse;
    }

    // Other implementations
}

If you have roles in your application you may also want to implement a custom role provider:

http://msdn.microsoft.com/en-us/library/8fw7xh74(v=vs.100).aspx

Post a Comment for "How To Configure Member Ship With A Database Other Than Aspnetdb"