I have been wrestling with this for the better part of the last three days, and I'm loosing my mind :)
I set up asp.net membership for Umbraco and I got the profile working. I create a profile for each new member, the initial data can be seen in the Umbraco back end, and I also created a usercontrol to show the data and that works as well.
This same user control needs to update the data. I made a save button and put the following code in the onclick event:
try
{
var profile = (MemberProfile)HttpContext.Current.Profile;
profile[
"fullName"] = tbFullName.Text;
profile[
"country"] = tbCountry.Text;
profile[
"city"] = tbCity.Text;
profile[
"streetAddress"] = tbStreeAddress.Text;
profile[
"phoneNumber"] = tbPhoneNumber.Text;
//profile.fullName = tbFullName.Text;
//profile.country = tbCountry.Text;
//profile.city = tbCity.Text;
//profile.streetAddress = tbStreeAddress.Text;
//profile.phoneNumber = tbPhoneNumber.Text;
profile.Save();
}
catch (Exception ex)
As you can see I tried setting the properties both ways (and a bunch of others I found on the net) and nothing works.
I initially only created a profile class. Then I tried adding the properties to the web.config, but got an error that the properties had already been defined, so I removed it.
I can't find any good information on this subject on the internet. Does anyone have this working?
I see that they don't have a special profile class. Do I need to drop the custom profile class all together and just work with the web.config properties and only access the base profile class?
Personally I am using the custom profile class and it's working fine, so I can't speak for the other method. In my case I do have the properties defined in the web.config. The following code works:
The duplicate property error can be resolved by making your property aliases different than they are named in the profile class. There is a comment about this as well as some instructions to setup the profile class on Aaron's blog
[SettingsAllowAnonymous(false)] public string FirstName { get { var o = base.GetPropertyValue("mFirstName"); if (o == DBNull.Value) { return string.Empty; } return (string)o; } set { base.SetPropertyValue("mFirstName", value); } }
Notice in the class it's FirstName but it updates the mFirstName property.
Ok. I got the web.config values and class values to live together, but still the update does not work.
I tried it everywhich way. I also tried the SetPropertyValue method as suggested above and nothing works.
I run the update and save code in an event handler for a click event of a usercontrol and after the postback I see the old value (old value in the backend ass well).
I don't get any error or exception. I put the block inside a try...catch and I get nothing. I have no idea what the problem is. Any ideas?
I guess that would be the first thing to do, no? :)
I did and it just goes throught the code. No error, no exception, and on the other hand no saving. Nothing...
I looked at the Profile editor macro you pointed me to, and it looks like they are accessing the XML schema directly, but they do everything a little differently, in order to remain generic. I can't seem to replicate what they are doing exactly.
When you updated your properties did you update the get and set of the property in the profile class to match? Can you maybe paste part of your class, the web.config entry, and the member property alias?
Do you found a solution? I got the same problem. I can update the properties on my custom table in umbraco backend, then i can read it in my user control. But I can update the profile. No error, no exception, no save....
Update member profile
Hi,
I have been wrestling with this for the better part of the last three days, and I'm loosing my mind :)
I set up asp.net membership for Umbraco and I got the profile working. I create a profile for each new member, the initial data can be seen in the Umbraco back end, and I also created a usercontrol to show the data and that works as well.
This same user control needs to update the data. I made a save button and put the following code in the onclick event:
As you can see I tried setting the properties both ways (and a bunch of others I found on the net) and nothing works.
I initially only created a profile class. Then I tried adding the properties to the web.config, but got an error that the properties had already been defined, so I removed it.
I can't find any good information on this subject on the internet. Does anyone have this working?
Thank you!
see if this help you out, source code is available http://our.umbraco.org/projects/website-utilities/profile-editor-macro
Thanks!
I'll check it out.
I see that they don't have a special profile class. Do I need to drop the custom profile class all together and just work with the web.config properties and only access the base profile class?
I think you should be able to make it work both ways, I didn't know this package, looks useful :-)
Did you also check out Aaron Powell's post on member profiles?
http://www.aaron-powell.com/umbraco-members-profiles
Hi,
Personally I am using the custom profile class and it's working fine, so I can't speak for the other method. In my case I do have the properties defined in the web.config. The following code works:
The duplicate property error can be resolved by making your property aliases different than they are named in the profile class. There is a comment about this as well as some instructions to setup the profile class on Aaron's blog
Hope this helps,
Tom
@Tom - Thanks for the reply. There is something I don't get.
Let take one property for example. In umbraco it's name is "Full Name" and it's alias is fullName.
In the web.config it has the following line:
Now in the profile class it is defined as:
[
SettingsAllowAnonymous(false)]
public string fullName
{
get
{
var o = base.GetPropertyValue("fullName");
if (o == DBNull.Value)
{
return string.Empty;}
return (string)o;
}
set
{
base.SetPropertyValue("fullName", value);
What should I change? Sorry, but I don't really get it. Thanks!
Hi Elad,
The property name in your class should be different than the field name. Here's an example:
Property Alias on Member Type: mFirstName
web.config:
Member Profile class
Notice in the class it's FirstName but it updates the mFirstName property.
Hope this helps,
Tom
Ok. I got the web.config values and class values to live together, but still the update does not work.
I tried it everywhich way. I also tried the SetPropertyValue method as suggested above and nothing works.
I run the update and save code in an event handler for a click event of a usercontrol and after the postback I see the old value (old value in the backend ass well).
I don't get any error or exception. I put the block inside a try...catch and I get nothing. I have no idea what the problem is. Any ideas?
did you try to debug your usercontrol ? :)
I guess that would be the first thing to do, no? :)
I did and it just goes throught the code. No error, no exception, and on the other hand no saving. Nothing...
I looked at the Profile editor macro you pointed me to, and it looks like they are accessing the XML schema directly, but they do everything a little differently, in order to remain generic. I can't seem to replicate what they are doing exactly.
Hi Elad,
When you updated your properties did you update the get and set of the property in the profile class to match? Can you maybe paste part of your class, the web.config entry, and the member property alias?
-Tom
Hi Tom,
Thanks for your reply!
I changed the names of the class members, not the names aliases of the properties.
For example the full name property.
In Umbraco it has an alias of fullName.
In the web.config:
<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" inherits="UmbracoMembership.MemberProfile, Membership">
<providers>
<clear />
<add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
</providers>
<properties>
<clear />
<add name="fullName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
</properties>
</profile>
In the profile class:
public
{
{
return (MemberProfile)Create(username);
}
GetUserProfile()
{
return (MemberProfile)Create(System.Web.Security.Membership.GetUser().UserName);
}
[
SettingsAllowAnonymous(false)]
{
get{var o = base.GetPropertyValue("fullName");
{
return string.Empty;}
set{base.SetPropertyValue("fullName", value);
And the property is set like so:
var
profile = (MemberProfile)HttpContext.Current.Profile;
profile._FullName = tbFullName.Text;
profile.Save();
I saw that the asp.net profile provider allows you to put properties in to groups.
In the Umbraco backend I have my properties on a "Personal Details" tab,
maybe I need to reflect this in the web.config as well for it to work?
(might be a stupid idea, but I'm running out of good ones!)
Do you found a solution? I got the same problem. I can update the properties on my custom table in umbraco backend, then i can read it in my user control. But I can update the profile. No error, no exception, no save....
thanks
oups double post!
is working on a reply...