Adding a new profile property is not very intuitive, so I thought I would write a quick how-to on it.

Let say we have a new property called "TaxPercentage, first of all you need to add the following line to Webpages->Web.config under system.web->profile->properties.

<add name="TaxPercentage" type="System.String" defaultValue="" />

, that takes care of the ASP.NET declerative part, now for our code.

First, open AzureTableStorage->UserEntity.cs and add the following line in the profile region:

public string TaxPercentage { get; set; }        

, this defines the entity.

Now we need to tell the profile provider that we have a new property too, so open WebPages->Bll->AzureProfileProvider.cs and add the following to the PropertyNames structure:

   public const string TaxPercentage = "TaxPercentage";

Then go to the SetPropertyValues() method, there you will find a large switch block (yes, yes, bad bad bad... I must refactor this sometime. ) and add the following line:

case PropertyNames.TaxPercentage:
   userEntity.TaxPercentage = (string)pv.PropertyValue;
   break;

, this is the code called when you store a property.

Then go to the GetPropertyValues() method, there also you will find a large switch block and add the following line:

case PropertyNames.TaxPercentage:
   pv.PropertyValue = userEntity.TaxPercentage;
   break;

Thats it, I will refactor this when I have some spare time, this is just too hard as it is at the moment.

Last edited May 7, 2012 at 9:03 AM by ihenriksen, version 2

Comments

No comments yet.