[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

User profile Serialization.

In order to show the information of the following class do I need to serialize this?
Or it is already since it is defined in the web.config? see attached code.
How would I serialize the code.

 <properties>
        <group name="Personal">
          <add name="UserName" type="System.String"/>
          <add name="Password" type="System.String" />
          <add name="Email" type="System.String"/>
          <add name="FirstName" type="System.String"/>
          <add name="LastName" type="System.String" />
          <add name="DOB" type="System.DateTime" />
          <add name="Age" type="System.Int32" />
          <add name="Gender" type="System.String"/>
          <add name="Seeking" type="System.String"/>
          <add name="ConfirmationGUID"  type="System.String"/>
          <add name="UserIP"  type="System.String"/>
          <add name="SessionID"  type="System.String"/>
        </group>
       
        <group name="Address">
          <add name="Country" type="System.String"/>
          <add name="Region" type="System.String"/>
          <add name="City"  type="System.String"/>
          <add name="ZipCode" type="System.String"/>
        </group>

        <group name="Preferences">
          <add name="Theme" type="String" allowAnonymous="false"/>
          <add name="Culture" type="String" defaultValue="en-US"/>
        </group>
      </properties>
    </profile>


using System;
using System.Web;
using System.IO;
using System.Xml.Serialization;
using System.Web.Caching;
 
public static class UserProfile
{
    public class Personal
    {
        public static System.String UserName
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("UserName") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("UserName", value); }
        }
 
        public static System.String Password
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Password") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Password", value); }
        }
 
        public static System.String Email
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Email") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Email", value); }
        }
 
        public static System.String FirstName
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("FirstName") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("FirstName", value); }
        }
 
        public static System.String LastName
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("LastName") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("LastName", value); }
        }
 
        public static System.DateTime DOB
        {
            get { return (System.DateTime)HttpContext.Current.Profile.GetPropertyValue("DOB"); }
            set { HttpContext.Current.Profile.SetPropertyValue("DOB", value); }
        }
 
        public static System.Int32? Age
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Age") as System.Int32?; }
            set { HttpContext.Current.Profile.SetPropertyValue("Age", value); }
        }
 
        public static System.String Gender
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Gender") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Gender", value); }
        }
 
        public static System.String Seeking
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Seeking") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Seeking", value); }
        }
 
        public static System.String ConfirmationGUID
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("ConfirmationGUID") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("ConfirmationGUID", value); }
        }
 
        public static System.String UserIP
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("UserIP") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("UserIP", value); }
        }
 
        public static System.String SessionID
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("SessionID") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("SessionID", value); }
        }
 
    }
    public class Address
    {
        public static System.String Country
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Country") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Country", value); }
        }
 
        public static System.String Region
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Region") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Region", value); }
        }
 
        public static System.String City
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("City") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("City", value); }
        }
 
        public static System.String ZipCode
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("ZipCode") as System.String; }
            set { HttpContext.Current.Profile.SetPropertyValue("ZipCode", value); }
        }
 
    }
    public class Preferences
    {
        public static String Theme
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Theme") as String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Theme", value); }
        }
 
        public static String Culture
        {
            get { return HttpContext.Current.Profile.GetPropertyValue("Culture") as String; }
            set { HttpContext.Current.Profile.SetPropertyValue("Culture", value); }
        }
 
    }
    public static void Save()
    {
        HttpContext.Current.Profile.Save();
    }
}

Open in new window

0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 3
1 Solution
 
aibusinesssolutionsCommented:
You will need to set the defaultProvider in the web.config file so it will use your profile provider, but basic types like String and Int are serialized for you by asp.net when you define them in the web.config file.

Here is an example of using a custom provider: http://www.odetocode.com/articles/440.aspx
0
 
mathieu_cuprykAuthor Commented:
can u help me more i am confused.
0
 
mathieu_cuprykAuthor Commented:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


/// <summary>
/// Summary description for Personal
/// </summary>
[Serializable()]
public class Personal
{
    public Personal() { }

    public Personal

        (string username,
         string password,
         string email,
         string firstname,
         string lastname,
         DateTime dob,
         Int32? age,
         string gender,
         string seeking,
         string confirmationguid)
    {
        this.UserName = username;
        this.Password = password;
        this.Email = email;
        this.FirstName = firstname;
        this.LastName = lastname;
        this.DOB = dob;
        this.Age = age;
        this.Gender = gender;
        this.Seeking = seeking;
        this.ConfirmationGUID = confirmationguid;
    }    

    private string username = "";
    public string UserName
    {
         get { return username;}
         set { username = value;}
    }

    private string password = "";
    public string Password
    {
        get { return password;}
        set { password = value;}
   }

    private string email = "";
    public string Email
    {
        get { return email;}
        set { email = value;}
    }

    private string firstname = "";
    public string FirstName
    {
        get { return FirstName;}
        set { FirstName = value;}
    }

    private string lastname = "";
    public string LastName
    {
        get { return LastName;}
        set { LastName = value;}
    }

    private DateTime dob = DateTime.Now;
    public DateTime DOB
    {
        get { return DOB;}
        set { DOB = value;}
    }

    private Int32? age = 0;
    public Int32? Age
    {
        get { return Age;}
        set { Age = value;}
    }  

    private string gender = "";
    public string Gender
    {
        get { return Gender;}
        set { Gender = value;}  
    }

    private string seeking = "";
    public string Seeking
    {
        get { return Seeking;}
        set { Seeking = value;}
    }

    private string confirmationguid = "";
    public string ConfirmationGUID
    {
        get { return ConfirmationGUID;}
        set { ConfirmationGUID = value;}
 
    }


   
}
Can you check my class I created.
0
 
mathieu_cuprykAuthor Commented:
link did not help at all.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now