Wednesday, November 9, 2011

Asp.Net Profile Provider


In the Article "Asp.Net MemberShip and Role Provider.", We have seen how to conigure and use the in built Sql Server MemberShip Provider. In this continuation article, we will see the usage of SqlProfileProvider. In any application if you want to store the user information other than the Registration details like their address,user's interest, themes etc., you can use the SqlProfileProvider.

Implementing the SqlProfileProvider:

The Profile provider can be configured to the application by using the following settings in the web.config file.

ProfileProvider Settings:

The Profile provider settings are simple and striaght forward, the elements include the name of the profile provider and the properties of the profile which are to be stored. You can also use the group property of the profile provider in order to the group the elements.:
 <profile defaultProvider="Demo_ProfileProvider">
  <add name="Demo_ProfileProvider" connectionStringName="cnn" 
  applicationName="/" type="System.Web.Profile.SqlProfileProvider, 
  System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  <add name="Name" type="String"/>
  <add name="DateofBirth" type="DateTime"/>
  <add name="Place" type="string"/>
  <add name="Languages" type="string"/>
  <add name="AboutMe" type="String"/>
  <add name="Employer" type="String"/>
  <add name="Project" type="String"/>
  <add name="Designation" type="String"/>
  <add name="University" type="String"/>

Using the Profile profile properies to Save User Profiles:

The following code is used to save the users profiles.Profile.Save() method updates the profile data source with changed profile property values.
     public void SaveProfile()
            Profile.Name = txtfullname.Text;
            Profile.DateofBirth = Convert.ToDateTime(txtdateofbirth.Text);
            Profile.AboutMe = txtaboutme.Text;
            Profile.Designation = txtdesignation.Text;
            Profile.Employer = txtemployer.Text;
            Profile.Languages = txtlanguages.Text;
            Profile.Place = txtplace.Text;
            Profile.Project = txtproject.Text;
            Profile.University = txtusername.Text;

Points of Interest:

In order to save the profiles of user. You can Customize the Create User Wizard contorl or you can use custom create user wizard. One type of creat user wizard which is developed using javascript is attached with source code. You can find more informatin about the create user wizard in the following article "Java script Create User Wizard for Asp.Net ".


In this article we have seen a brief description about how to implement Profile provider and how we can use the profile properties in our application. You can find some more information about profile provider and their properties at the below MSDN Links.
External Resources:

No comments:

Post a Comment