title: Converting website with profiles to web application project
body: <p>I'm trying to convert an existing <a href="http://mywsat.codeplex.com/" rel="nofollow">website</a> to a Web Application Project and I'm having big problems getting the profiles to work.</p>
  
  <p>An example of codebehind in website project is</p>
  
  <p><strong>register-with-role-and-profile.ascx.cs</strong></p>
  
  <pre><code>    // Add the newly created user to the default Role.
      Roles.AddUserToRole(CreateUserWizard1.UserName, wsatDefaultRole);
  
      // Create an empty Profile for the newly created user
      ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
  
      // Populate some Profile properties. Values are located in web.config file
      p.Company.Company = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeName")).Text;
      p.Company.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeAddress")).Text;
      p.Company.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeCity")).Text;
      p.Company.State = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlStates")).SelectedValue;
      p.Company.PostalCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).Text;
      p.Company.Phone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactPhone")).Text;
      p.Company.Fax = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactFax")).Text;
      p.Preferences.Newsletter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlNewsletter")).SelectedValue;
  
      // Save profile - must be done since we explicitly created it
      p.Save();
  </code></pre>
  
  <p><strong>web.config</strong></p>
  
  <pre><code>&lt;profile defaultProvider="MyCMSTableProfileProvider" automaticSaveEnabled="false" enabled="true"&gt;
      &lt;providers&gt;
          &lt;clear/&gt;
          &lt;add name="MyCMSTableProfileProvider" applicationName="MyCMS" connectionStringName="dbMyCMSConnectionString" table="aspnet_CustomProfile" type="CustomProfile.SqlTableProfileProvider"/&gt;
          &lt;add name="MyCMSStoredProcedureProfileProvider" applicationName="MyCMS" connectionStringName="dbMyCMSConnectionString" type="CustomProfile.SqlStoredProcedureProfileProvider" setProcedure="sp_wsat_SetCustomProfileData" readProcedure="sp_wsat_GetCustomProfileData"/&gt;
      &lt;/providers&gt;
      &lt;properties&gt;
          &lt;group name="Personal"&gt;
              &lt;add name="FirstName" type="String" defaultValue="[null]" customProviderData="FirstName;nvarchar"/&gt;
              &lt;add name="LastName" type="String" defaultValue="[null]" customProviderData="LastName;nvarchar"/&gt;
              &lt;add name="Gender" type="String" defaultValue="[null]" customProviderData="Gender;nvarchar"/&gt;
              &lt;add name="BirthDate" type="DateTime" defaultValue="[null]" customProviderData="BirthDate;datetime"/&gt;
              &lt;add name="Occupation" type="String" defaultValue="[null]" customProviderData="Occupation;nvarchar"/&gt;
              &lt;add name="Website" type="String" defaultValue="[null]" customProviderData="PersonalWebsite;nvarchar"/&gt;
          &lt;/group&gt;
          &lt;group name="Address"&gt;
              &lt;add name="Country" type="String" defaultValue="[null]" customProviderData="Country;nvarchar"/&gt;
              &lt;add name="Address" type="String" defaultValue="[null]" customProviderData="Address;nvarchar"/&gt;
              &lt;add name="AptNumber" type="String" defaultValue="[null]" customProviderData="AptNumber;nvarchar"/&gt;
              &lt;add name="City" type="String" defaultValue="[null]" customProviderData="City;nvarchar"/&gt;
              &lt;add name="State" type="String" defaultValue="[null]" customProviderData="State;nvarchar"/&gt;
              &lt;add name="PostalCode" type="String" defaultValue="[null]" customProviderData="PostalCode;nvarchar"/&gt;
          &lt;/group&gt;
          &lt;group name="Contacts"&gt;
              &lt;add name="DayPhone" type="String" defaultValue="[null]" customProviderData="DayPhone;nvarchar"/&gt;
              &lt;add name="DayPhoneExt" type="String" defaultValue="[null]" customProviderData="DayPhoneExt;nvarchar"/&gt;
              &lt;add name="EveningPhone" type="String" defaultValue="[null]" customProviderData="EveningPhone;nvarchar"/&gt;
              &lt;add name="EveningPhoneExt" type="String" defaultValue="[null]" customProviderData="EveningPhoneExt;nvarchar"/&gt;
              &lt;add name="CellPhone" type="String" defaultValue="[null]" customProviderData="CellPhone;nvarchar"/&gt;
              &lt;add name="Fax" type="String" defaultValue="[null]" customProviderData="Fax;nvarchar"/&gt;
          &lt;/group&gt;
          &lt;group name="Company"&gt;
              &lt;add name="Company" type="String" defaultValue="[null]" customProviderData="Company;nvarchar"/&gt;
              &lt;add name="Address" type="String" defaultValue="[null]" customProviderData="Address2;nvarchar"/&gt;
              &lt;add name="City" type="String" defaultValue="[null]" customProviderData="City2;nvarchar"/&gt;
              &lt;add name="State" type="String" defaultValue="[null]" customProviderData="State2;nvarchar"/&gt;
              &lt;add name="PostalCode" type="String" defaultValue="[null]" customProviderData="PostalCode2;nvarchar"/&gt;
              &lt;add name="Phone" type="String" defaultValue="[null]" customProviderData="Phone2;nvarchar"/&gt;
              &lt;add name="Fax" type="String" defaultValue="[null]" customProviderData="Fax2;nvarchar"/&gt;
              &lt;add name="Website" type="String" defaultValue="[null]" customProviderData="Website2;nvarchar"/&gt;
          &lt;/group&gt;
          &lt;group name="Preferences"&gt;
              &lt;add name="Culture" type="String" defaultValue="en-US" customProviderData="Culture;nvarchar"/&gt;
              &lt;add name="Newsletter" type="String" defaultValue="[null]" customProviderData="Newsletter;nvarchar"/&gt;
          &lt;/group&gt;
      &lt;/properties&gt;
  &lt;/profile&gt;
  </code></pre>
  
  <p>but this gives error <code>The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)</code></p>
  
  <p>Using this <a href="http://www.codeproject.com/Articles/290929/Using-ASP-Net-Profile-Feature-in-a-Web-Application" rel="nofollow">example</a> I created 2 new classes</p>
  
  <p><strong>ProfileInfo.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace myWSAT.controls
  {
      [Serializable]
      public class Personal
      {
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Gender { get; set; }
          public DateTime BirthDate { get; set; }
          public string Occupation { get; set; }
          public string Website { get; set; }
      }
  
      [Serializable]
      public class Address
      {
          public string Country { get; set; }
          public string Address1 { get; set; }
          public string AptNumber { get; set; }
          public string City { get; set; }
          public string State { get; set; }
          public string PostalCode { get; set; }
      }
  
      [Serializable]
      public class Contacts
      {
          public string DayPhone { get; set; }
          public string DayPhoneExt { get; set; }
          public string EveningPhone { get; set; }
          public string EveningPhoneExt { get; set; }
          public string CellPhone { get; set; }
          public string Fax { get; set; }
  
      }
  
      [Serializable]
      public class Company
      {
          public string CompanyName { get; set; }
          public string Address { get; set; }
          public string City { get; set; }
          public string State { get; set; }
          public string PostalCode { get; set; }
          public string Phone { get; set; }
          public string Fax { get; set; }
          public string Website { get; set; }
  
      }
  
      [Serializable]
      public class Preferences
      {
          public string Culture { get; set; }
          public string Newsletter { get; set; }
  
      }
  
      [Serializable]
      public class ProfileInfo
      {
          public Personal Personal { get; set; }
          public Address Address { get; set; }
          public Contacts Contacts { get; set; }
          public Company Company { get; set; }
          public Preferences Preferences { get; set; }
      }
  
  }
  </code></pre>
  
  <p><strong>wProfile.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Web;
  using System.Web.Profile;
  
  namespace myWSAT.controls
  {
      public class wProfile : ProfileBase
      {
          public ProfileInfo ProfileInfo
          {
              get { return (ProfileInfo)GetPropertyValue("ProfileInfo"); }
          }
  
          public static wProfile GetProfile()
          {
              return (wProfile)HttpContext.Current.Profile;
          }
  
          public static wProfile GetProfile(string userName)
          {
              return (wProfile)Create(userName);
          }  
      }
  }
  </code></pre>
  
  <p>and then amended
  <strong>register-with-role-and-profile.ascx.cs</strong> to</p>
  
  <pre><code>// add newly created user to default Role specified above
  if (Roles.RoleExists(wsatDefaultRole))
  {
      // Add the newly created user to the default Role.
      Roles.AddUserToRole(CreateUserWizard1.UserName, wsatDefaultRole);
  
      // Create an empty Profile for the newly created user
      wProfile p = wProfile.GetProfile(Membership.GetUser().UserName);
      //ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
  
      // Populate some Profile properties. Values are located in web.config file
      p.ProfileInfo.Company.CompanyName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeName")).Text;
      p.ProfileInfo.Company.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeAddress")).Text;
      p.ProfileInfo.Company.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeCity")).Text;
      p.ProfileInfo.Company.State = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlStates")).SelectedValue;
      p.ProfileInfo.Company.PostalCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).Text;
      p.ProfileInfo.Company.Phone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactPhone")).Text;
      p.ProfileInfo.Company.Fax = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactFax")).Text;
      p.ProfileInfo.Preferences.Newsletter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlNewsletter")).SelectedValue;
  
      // Save profile - must be done since we explicitly created it
      p.Save();
  
  }
  </code></pre>
  
  <p>This build and runs okay but the following line always returns null.</p>
  
  <pre><code>wProfile p = wProfile.GetProfile(Membership.GetUser().UserName);
  </code></pre>
  
  <p>I'm not sure what is wrong? I've also tried the example in the bottom of this <a href="http://msdn.microsoft.com/en-us/library/aa983476.aspx" rel="nofollow">link</a> with no success </p>
  
  <p>EDIT:</p>
  
  <p>I have read lots of links and tried several of the solutions but my expertise is this area is not great. I guess I'm asking for a bit of help with syntax to get it running, I'll prob offer a bounty once I can.</p>
  
  <p>EDIT:
  It may help if I attach the current state of my attempt at converting this to a WAP. 
  <a href="http://www.mediafire.com/?ouabeoxwu75b52c" rel="nofollow">http://www.mediafire.com/?ouabeoxwu75b52c</a></p>