Search code examples
asp.netsql-server-2008asp.net-membership

Change ASP.NET Membership tables in database


I have my own database (SQL Server 2008 RQ) and i have a table name "Users" I wanna use ASP.NET MemberShip with my table (Users) how can i do this ?

I don't want to use normal DataBase, i wanna change tables and fields because i want to personalize it.

I don't want to use Profile, i want to change tables and fields, i know i can create my own authentication system but i want to use Login Control from ToolBox and other Controls.

Please give me suggestions.


Solution

  • This is fairly easy. You just have to create your own class inheriting from MembershipProvider and register it as a default provider. One of its methods in particular is designed to validate users' credentials. The builtin Login will use your own code, as long as you register your provider.

    public class MyCustomMembershipProvider : MembershipProvider {
       // a lot of methods required by the abstract class
    
       public bool ValidateUser( string UserName, string Password ) {
          // use your own database to validate user credentials
       }
    }
    

    and then

    <system.web>
       <membership defaultProvider="MyCustomMembershipProvider">
          <providers>
             <add name="MyCustomMembershipProvider" type="MyCustomMembershipProvider" />
          </providers>
       </membership>
    

    In case of any doubts, follow the example:

    http://msdn.microsoft.com/en-us/library/44w5aswa.aspx