ASP.Net Profiles: Configuring Difficulty and Using Profile Fields

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

+7
source share
1 answer

Defining custom properties in web.config, as well as a class that inherits from ProfileBase, seems redundant:

Notes to the heirs

You can create a custom profile implementation that inherits from the abstract ProfileBase class and defines properties for the user profile that are not specified in the profile configuration item.

http://msdn.microsoft.com/en-us/library/system.web.profile.profilebase.aspx

Also: Have you changed the code for XmlProfileProvider? It seems to be expecting an XmlProfile and nothing more.

http://www.java2s.com/Open-Source/ASP.NET/Asp.net-Samples/tinyproviders/Artem/Web/Security/XmlProfileProvider.cs.htm

+5
source

All Articles