I am currently trying to use ASP.Net profiles to store additional information about users registered on our site.
Relevant code example:
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 FacebookUid defined in web.config; I get this error from web.config:
Configuration Error: This profile property has already been defined.
I double checked web.config; this property record occurs only once in the web.config file.
I realized that this is due to the fact that I am setting a property with the same name in the UserProfile class. I removed the properties / added the [name = 'FacebookUid] entry from web.config. When I did it; I get this error when I try to set the FacebookUid value in Register.aspx.cs:
The settings property 'FacebookUid' was not found Line 76: profile["FacebookUid"] = "";
I tried again, this time directly using the ProfileBase class:
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 / add [name = 'FacebookUid'] properties and without; received the same errors as above in the same cases.
I'm at a standstill, and Googling / Binging is useless. Does anyone here know what can happen and / or how to solve this problem? Any constructive input is appreciated.
Thanks Frank