How to Extend User Profile in ASP.Net 2.0


Introduction

ASP.Net 2.0 is shipped with membership provider as well as Role provider.

By default, the membership provider comes with standard profile for users through building membership tables in your application database.

In business application, you need to extend the user profile table by adding new fields in that profile, I will mention one of the approaches to achieve this instead of creating custom membership from scratch.

Overview

This article will give you guidelines to extend user profile in standard table format which created from aspnet_regsql command by creating a detail table which will be linked to the main user table.

Prerequisites

  1. Visual Studio 2005
  2. MS SQL 2000/SQL 2005

Solution

The idea is to extend the aspnet user table by creating another table in your database with the required fields you want in your application based on your business requirements and specs.

See the below figure to see the extended table as will as the relation between the tables.

This solution is solve the problem if you need any extra fields you want to add it on your application, and at the same time it gives you the full functionality of the membership provider on web.config on your application.

Let's see the code to manage users in this solution

For example: Creating the user:

Code below shows the creation for user in aspnet user table and get the aspnetuserId and pass it as input parameter on your insert stored procedure to link the added user to your table in your database.

// insert the user in aspnet users.

MembershipUser usr = Membership.CreateUser(Username, Username, Email);

string aspnetUserId = "{" + usr.ProviderUserKey.ToString() + "}";

Guid gdAspnetUserId = new Guid(aspnetUserId);

// insert in your users table

UsersTableAdapter UserTA = new UsersTableAdapter();

UserTA.SP_Users_Insert(gdAspnetUserId, Username, Email, Address); //Your Paramaters

Conclusion

This article states a solution to extend default aspnetuser table in asp.net 2.0 to meet your requirements in any application you plan to extend the user profile.

Up Next
    Ebook Download
    View all
    Learn
    View all