I'm currently trying to use ASP.Net Profiles to store additional user information about users that register on our site.
Relevant sample code:
UserProfile.cs
public class UserProfile: System.Web.Profile.ProfileBase
{
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return GetUserProfile(Membership.GetUser().UserName);
}
public string FacebookUid
{
get
{
return base["FacebookUid"] as string;
}
set
{
base["FacebookUid"] = value;
}
}
}
Web.config
<profile enabled="true" inherits="WIF.Web.STS.Classes.UserProfile" defaultProvider="XmlProfileProvider" >
<properties>
<add name="FacebookUid" />
</properties>
<providers>
<add name="XmlProfileProvider" type="Artem.Web.Security.XmlProfileProvider, Artem.Web.Security.Xml" applicationName="/" fileName="Profiles.xml" folder="~/App_Data/"/>
</providers>
</profile>
Register.aspx.cs
profile = WIF.Web.STS.Classes.UserProfile.GetUserProfile(emailAddress);
profile.FacebookUid = "";
When I leave the FacebookUid defined in the web.config; I get this error from the web.config:
Configuration Error: This profile property has already been defined.
I've double checked the web.config; that property entry only occurs once in the web.config.
I figured this is because I setup the property with the same name on the UserProfile class. I removed the properties/add[name='FacebookUid'] entry from the web.config. Once I did that; I get this error when I try to set the value of FacebookUid in Register.aspx.cs:
The settings property 'FacebookUid' was not found
Line 76: profile["FacebookUid"] = "";
I tried one more time, this time using the ProfileBase class directly:
Revised Register.aspx.cs
var profile = System.Web.Profile.ProfileBase.Create(emailAddress,true);
profile["FacebookUid"] = "";
Revised web.config:
<profile enabled="true" defaultProvider="XmlProfileProvider" >
<properties>
<add name="FacebookUid" />
</properties>
<providers>
<add name="XmlProfileProvider" type="Artem.Web.Security.XmlProfileProvider, Artem.Web.Security.Xml" applicationName="/" fileName="Profiles.xml" folder="~/App_Data/"/>
</providers>
</profile>
I tried this with properties/add[name='FacebookUid'] and without; got the same errors as above in the same cases.
I'm stumped and Googling/Binging has gotten me nowhere. Does anyone here have any idea what might be going on and/or how to fix this problem? Any constructive input is greatly appreciated.
Thanks, Frank