I have a custom registration form using the asp.net membership provider. I have also created a custom profile provider as well. After registration, I want to set some settings into the profile for the user (address, etc).
Here are the steps I took:
Created a user typed called "Registered User" (alias "RegisteredUser") under Member Types.
Added a generic property of type string called "Address"
Tweak the web.config to include the default provider and default member type.
Created a profile that inherits from ProfileBase with a public property of Address, accessing underlying base member "Address"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
namespace NPS10x10.Umbraco.Profile
{
public class NPSProfile : ProfileBase
{
public static NPSProfile CurrentUser
{
get
{
return (NPSProfile)(ProfileBase.Create(Membership.GetUser().UserName));
}
}
public static NPSProfile GetUser(string userName)
{
return (NPSProfile)(ProfileBase.Create(userName));
}
public string Address
{
get
{
return ((string)(base["Address"]));
}
set
{
base["address"] = value;
Save();
}
}
}
}
I let the framekwork create the user.
On created user callback (inherited from the registration wizard page), I get the user profile for the new user using default framework code [ (NPSProfile )ProfileBase.Create(userName) ]
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.propertytype;
using umbraco.interfaces;
namespace NPS10x10.Umbraco
{
public partial class NPSRegister : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Profile.NPSProfile p =
Profile.NPSProfile.GetUser(
(WizardStep1.ContentTemplateContainer.FindControl("UserName") as TextBox).Text);
p.Address = (WizardStep1.ContentTemplateContainer.FindControl("textAddress") as TextBox).Text;
p.Save();
}
}
}
Problem is, value is never saved to the database. When it loops through the values of my customer profile in the member profile provider (umbraco) it never finds the match. The m.getProperty(spv.Name) check below always comes back null. spv.Name does have the "Address" value for name, and the address property does exist for the member type "RegisteredUser"
MemberProfileProvider.cs line #149-155:
foreach (SettingsPropertyValue spv in collection) {
if (!authenticated && !(bool)spv.Property.Attributes["AllowAnonymous"])
continue;
if (m.getProperty(spv.Name) != null)
m.getProperty(spv.Name).Value = spv.PropertyValue;
}
Is there something I'm missing? Logically, this code should work.
one more commet (tried editing but throws xslt error). I have commented out the Address addition to the profile provider section in the web.config because if I add it an error is thrown saying it already exists (as well as all of the other types I have been trying). I've tried to do a <clear /> first but that failed. There are no other instances of this in the web.config
I've made some headway on this. The member type property is names "Address" and the alias is "address". The .Net code uses "Address" for the property and populates the base value of "address". It seems that it's a casing issue. I figured the simplist way to resolve the problem would be to change the alias name to "Address", but it gives me an error when I use "A" instead of "a".
Riddle me this: Why?
Does this mean that I need to ensure all my .Net properties name start with lower case?
Looking at the last code I used, it appears that we created our own profile provider which inherits ProfileBase and use that to set the values of the base using the lower cased properties. We also omitted all of the lines from the web.config description the properties (only a reference to the provider). By doing this, our profile class has more meaningful names (such as FirstName instead of firstName). We also added a couple static helper methods to get the current profile so you can just do CurrentProfile.FirstName
public string LastName { get { return ((string)(base["lastname"])); } set { base["lastname"] = value; Save(); } }
I've made some headway on
this. The member type property is names "Address" and the alias is
"address". The .Net code uses "Address" for the property and populates
the base value of "address". It seems that it's a casing issue. I
figured the simplist way to resolve the problem would be to change the
alias name to "Address", but it gives me an error when I use "A" instead
of "a".
I'm having the same issue here. I've been following http://www.aaron-powell.com/umbraco-members-profiles and couldn't figure out why it wasn't working. I have created a profile provider which inherits from ProfileBase and the corresponding member type property only gets written to if the name of the property name in the provider is in lower case.
The provider code is like so:
public class MemberProfileTest : ProfileBase { public static MemberProfileTest GetMemberProfile(string username) { return Create(username) as MemberProfileTest; }
[SettingsAllowAnonymous(false)] public string Age { get { var o = base.GetPropertyValue("age"); if (o == DBNull.Value) { return string.Empty; } return (string)o; } set { base.SetPropertyValue("age", value); } } }
Solved my problem. It seems you can do one of two things.
Either add the properties you want to access to the 'properties' part of profile section in the web.config using the Umbraco alias names and then create properties in your provider with different names.
or
Don't bother adding the 'properties' part of profile section in the web.config and just create properties in your provider class, but making sure you name them exactly the same (including the case) as the Umbraco alias.
My problem was that the case was inconsistent so it didn't work.
Old thread, but just wanted to say thanks Matt! I have a plethora of custom properties in my provider class, but I had been naming them differently, which then required a matching number of entries in the web.config.... very annoying. By keeping the name (and case) consistent with the Umbraco alias, I was able to avoid having to fill up my web.config and save some labor in the process.
member profile problem 4.5.x
I have a custom registration form using the asp.net membership provider. I have also created a custom profile provider as well. After registration, I want to set some settings into the profile for the user (address, etc).
Here are the steps I took:
Problem is, value is never saved to the database. When it loops through the values of my customer profile in the member profile provider (umbraco) it never finds the match. The m.getProperty(spv.Name) check below always comes back null. spv.Name does have the "Address" value for name, and the address property does exist for the member type "RegisteredUser"
Is there something I'm missing? Logically, this code should work.
one more commet (tried editing but throws xslt error). I have commented out the Address addition to the profile provider section in the web.config because if I add it an error is thrown saying it already exists (as well as all of the other types I have been trying). I've tried to do a <clear /> first but that failed. There are no other instances of this in the web.config
I've made some headway on this. The member type property is names "Address" and the alias is "address". The .Net code uses "Address" for the property and populates the base value of "address". It seems that it's a casing issue. I figured the simplist way to resolve the problem would be to change the alias name to "Address", but it gives me an error when I use "A" instead of "a".
Riddle me this: Why?
Does this mean that I need to ensure all my .Net properties name start with lower case?
Did you ever figure this out?
Looking at the last code I used, it appears that we created our own profile provider which inherits ProfileBase and use that to set the values of the base using the lower cased properties. We also omitted all of the lines from the web.config description the properties (only a reference to the provider). By doing this, our profile class has more meaningful names (such as FirstName instead of firstName). We also added a couple static helper methods to get the current profile so you can just do CurrentProfile.FirstName
From above ...
I've made some headway on this. The member type property is names "Address" and the alias is "address". The .Net code uses "Address" for the property and populates the base value of "address". It seems that it's a casing issue. I figured the simplist way to resolve the problem would be to change the alias name to "Address", but it gives me an error when I use "A" instead of "a".
I'm having the same issue here. I've been following http://www.aaron-powell.com/umbraco-members-profiles and couldn't figure out why it wasn't working.
I have created a profile provider which inherits from ProfileBase and the corresponding member type property only gets written to if the name of the property name in the provider is in lower case.
The provider code is like so:
I'm setting the profile values like this:
The web.config looks like this:
As I say, for some reason it does not work unless I change the case of the provider property to
and set the value like so
Any idea why this would be?
Regards,
Matt
Solved my problem.
It seems you can do one of two things.
Either add the properties you want to access to the 'properties' part of profile section in the web.config using the Umbraco alias names and then create properties in your provider with different names.
or
Don't bother adding the 'properties' part of profile section in the web.config and just create properties in your provider class, but making sure you name them exactly the same (including the case) as the Umbraco alias.
My problem was that the case was inconsistent so it didn't work.
Old thread, but just wanted to say thanks Matt! I have a plethora of custom properties in my provider class, but I had been naming them differently, which then required a matching number of entries in the web.config.... very annoying. By keeping the name (and case) consistent with the Umbraco alias, I was able to avoid having to fill up my web.config and save some labor in the process.
Cheers!
is working on a reply...