---
title: "Profile in ASP.net"  
description: "The ASP.NET Framework provides an alternative to using cookies or Session state to store user information as a Profile object. When a user visits your"  
author: "Chris Anderson"  
published: 2011-08-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/225/profile-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Profile in ASP.net

The ASP.NET [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) provides an [alternative](https://www.mindstick.com/forum/2324/what-is-the-alternative-to-the-mvc) to using cookies or Session state to store user information as a Profile object. When a user visits [your site](https://www.mindstick.com/articles/12865/infographic-drive-traffic-to-your-site-in-2018-10-hints), you can use the information you have stored to present the user with a personalized version of your [Web application](https://www.mindstick.com/articles/13069/progressive-web-application-pwas-all-you-need-to-know-about). Personalizing an application requires a number of [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements): you must store the information using a unique user identifier, be able to recognize users when they visit again, and then fetch the user information as needed. To simplify your [applications](https://www.mindstick.com/articles/12847/how-to-choose-the-right-ethernet-cable-for-industrial-applications), you can use the ASP.NET profile feature, which can perform all of these tasks for you.

The Profile object provides you with a strongly typed, persistent form of session state.\
You create a Profile by defining a list of Profile [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) in your application root web\
[configuration](https://www.mindstick.com/articles/13112/setting-up-the-perfect-configuration-for-your-work-computer) file. The ASP.NET Framework dynamically compiles a class that contains these properties in the background.

##### HOW TO CREATE AND USE PROFILE?

##### \
File: Web.Config

```
<configuration>                 <system.web>                     <profile>                        <properties>                            <add name="Name"/>                           <add name="Age" type="System.Int16" />                           <add name="numberOfVisits" type="Int32" defaultValue="0" />                        </properties>                     </profile>                 </system.web></configuration> 
```

##### File: ShowProfile.aspx

```
                <html xmlns="http://www.w3.org/1999/xhtml">    <head runat="server">           <title></title>    <script runat="server">              protected void Page_Load(object sender, EventArgs e)              {                     if (!Page.IsPostBack)                     {                           Profile.numberOfVisits++;                           nameTextBox.Text = Profile.Name;                           ageTextBox.Text = Profile.Age.ToString();                           lblNoOfVisit.Text = Profile.numberOfVisits.ToString();                     }              }              protected void updateProfileButton_Click(object sender, EventArgs e)              {                           Profile.Name = nameTextBox.Text;                           Profile.Age = Int16.Parse(ageTextBox.Text);              }          </script>   </head>   <body>              <form id="form1" runat="server">              <div>              <hr />                     <asp:TextBox runat="server" ID="nameTextBox" /><br />                     <asp:TextBox runat="server" ID="ageTextBox" /><br />                     <asp:Label runat="server" ID="lblNoOfVisit"></asp:Label><br />                     <asp:Button runat="server" ID="updateProfileButton" Text="Save                                  Preferences" OnClick="updateProfileButton_Click" />               </div>              </form>   </body>   </html>
```

The above code creates profile by using [web.config](https://www.mindstick.com/forum/183/web-config-file) file and stores user information in profile object and also display’s the information of user by using profile object.

---

Original Source: https://www.mindstick.com/blog/225/profile-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
