Search code examples
c#asp.netvisual-studio-2010asp.net-profiles

Profile Common in Visual Web Developer 2010 Website


I know that ProfileCommon is not available in a Web Application Project (WAP), but I am using the Website type instead. I put this into my web.config file

<system.web>
  <profile enabled="true">
    <properties>
      <add name="FirstName" type="System.String"/>
      <add name="LastName" type="System.String"/>
      <add name="Address" type="System.String"/>
      <add name="City" type="System.String"/>
      <add name="State" type="System.String"/>
      <add name="Zip" type="System.String"/>
      <add name="Email" type="System.String"/>
      <add name="Birthday" type="System.String"/>
      <add name="ProfilePicture" type="System.String"/>
      <add name="ProfilePictureThumb" type="System.String"/>
    </properties>
  </profile>
  <roleManager enabled="true"></roleManager>
</system.web>

and when I try to add the

ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;

statement into a .cs file I get the

The type or namespace name 'ProfileCommon' could not be found (are you missing a using directiv or assembly reference)

I am using the imports

using System;
using System.Web;
using System.Web.Security;
using System.Web.Profile;

Solution

  • This blog post will help you : WebProfile Builder and WAP for VS2010

    ProfileCommon is dynamic class. you can create instant of that using below line of code.

    var profile = HttpContext.Current.Profile;
    

    enter image description here

    If you need to set property values:

    profile.SetPropertyValue("FirstName","testName");