Tuesday, December 20, 2011

Profile in asp.net

Server Side State Management
(Profile Property,Session,Application)

For Session: Click to View Example

For Application State:  Click to View Example

Application State:
(msdn defination)

ASP.NET provides a feature called profile properties, which allows you to store user-specific data. This feature is similar to session state, except that the profile data is not lost when a user's session expires. The profile-properties feature uses an ASP.NET profile, which is stored in a persistent format and associated with an individual user. The ASP.NET profile allows you to easily manage user information without requiring you to create and maintain your own database. In addition, the profile makes the user information available using a strongly typed API that you can access from anywhere in your application. You can store objects of any type in the profile. The ASP.NET profile feature provides a generic storage system that allows you to define and maintain almost any kind of data while still making the data available in a type-safe manner.


To use profile properties, you must configure a profile provider. ASP.NET includes a SqlProfileProvider class that allows you to store profile data in a SQL database, but you can also create your own profile provider class that stores profile data in a custom format and to a custom storage mechanism such as an XML file, or even to a web service.

Because data that is placed in profile properties is not stored in application memory, it is preserved through Internet Information Services (IIS) restarts and worker-process restarts without losing data. Additionally, profile properties can be persisted across multiple processes such as in a Web farm or a Web garden. For more information, see ASP.NET Profile Properties Overview.



Example

in web.config file

<profile defaultProvider="AspNetSqlProfileProvider">
  <properties>
     <add name="Name" />
     <add name="Weight" type="System.Int32" />
     <add name="BirthDate" 
          type="System.DateTime" />
  </properties>
</profile>
in .cs page
DateTime bday = Profile.BirthDate;
LblName.Text=Profile.Name;
Response.Write("Name:"+LblName.Text);
Response.Write("Dob:"+ bday.toString());


No comments:

Post a Comment