I created a class that extends ProfileBase:
public class CustomerProfile : ProfileBase
{
public int CustomerID { get; set; }
public string CustomerName { get; set; }
public static CustomerProfile GetProfile()
{
return Create(Membership.GetUser().UserName) as CustomerProfile;
}
public static CustomerProfile GetProfile(string userName)
{
return Create(userName) as CustomerProfile;
}
}
If I do:
CustomerProfile p = CustomerProfile.GetProfile();
p.CustomerID = 1;
p.Save();
The next time I try to access the value for the current user, it is not 1, it is 0, so it appears it is not saving it in the database.
In my web.config file I have the following snippet:
<profile inherits="PortalBLL.CustomerProfile">
<providers>
<add name="CustomerProfile" type="System.Web.Profile.SqlProfileProvider" applicationName="/" connectionStringName="LocalSqlServer"/>
</providers>
</profile>
I tried the following and it worked, I am curious why it doesn't save it using the automatic properties.
[SettingsAllowAnonymous(false)]
public int CustomerID
{
get { return (int)base.GetPropertyValue("CustomerID");}
set { base.SetPropertyValue("CustomerID",value);}
}