Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 13:09
    Elad Lachmi
    0

    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:

     

     

     

     

     

     

     

     

     

     

     

    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?

    Thank you!

  • Eran Meir 401 posts 543 karma points
    Apr 25, 2011 @ 13:32
    Eran Meir
    1

    see if this help you out, source code is available http://our.umbraco.org/projects/website-utilities/profile-editor-macro

  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 13:42
    Elad Lachmi
    0

    Thanks!

    I'll check it out.

  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 13:45
    Elad Lachmi
    0

    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?

  • Lennart Stoop 304 posts 842 karma points
    Apr 25, 2011 @ 14:11
    Lennart Stoop
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 25, 2011 @ 14:16
    Tom Fulton
    0

    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:

                MemberProfile mp = ((MemberProfile)HttpContext.Current.Profile);
                mp
    .SetPropertyValue("mFirstName", FirstName.Text);
                mp
    .SetPropertyValue("mLastName", LastName.Text);

    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

  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 17:01
    Elad Lachmi
    0

    @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:

    <add name="fullName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />

    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!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 25, 2011 @ 17:04
    Tom Fulton
    0

    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:

    <add name="mFirstName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />

    Member Profile class

            [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.

    Hope this helps,
    Tom

  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 17:37
    Elad Lachmi
    0

    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?

  • Eran Meir 401 posts 543 karma points
    Apr 25, 2011 @ 19:06
    Eran Meir
    0

    did you try to debug your usercontrol ? :)

  • Elad Lachmi 112 posts 144 karma points
    Apr 25, 2011 @ 23:46
    Elad Lachmi
    0

    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.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 26, 2011 @ 14:15
    Tom Fulton
    0

    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

  • Elad Lachmi 112 posts 144 karma points
    Apr 26, 2011 @ 17:31
    Elad Lachmi
    0

    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

     

     

     

    class MemberProfile : ProfileBase

    {

     

    public static MemberProfile GetUserProfile(string username)

    {

     

    return (MemberProfile)Create(username);

    }

     

    public static MemberProfile

    GetUserProfile()

    {

     

    return (MemberProfile)Create(System.Web.Security.Membership.GetUser().UserName);

    }

    [

     

    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);

     

    And the property is set like so:

    var

     

     

    profile = (MemberProfile)HttpContext.Current.Profile;

    profile._FullName = tbFullName.Text;

    profile.Save();

  • Elad Lachmi 112 posts 144 karma points
    Apr 28, 2011 @ 07:33
    Elad Lachmi
    0

    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!)

  • PierreD Savard 183 posts 290 karma points
    Feb 12, 2013 @ 19:47
    PierreD Savard
    0

    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

  • PierreD Savard 183 posts 290 karma points
    Feb 12, 2013 @ 19:58
    PierreD Savard
    0

    oups double post!

Please Sign in or register to post replies

Write your reply to:

Draft