views:

584

answers:

1

Hi,

I've created my own signup form and creating the user using the Membership class.

 MembershipCreateStatus status;
            MembershipUser newUser = Membership.CreateUser(tbxUsername.Text, tbxPassword.Text, tbxEmail.Text, null, null, true, out status);

After the user is created using the code about, I try to set some profile properties like so

 Profile.CountryCode = ddlCountry.SelectedValue;
                    Profile.DisplayName = tbxDisplayName.Text;
                    Profile.Save();

However I get the following exception message

This property cannot be set for anonymous users.

Any ideas why im getting this?

+2  A: 

I Think this is beacuse you didn't fetched the profile first (from DB/Whatever you are using).

you code might look like the following:

ProfileCommon p = Profile.GetProfile(tbxUsername.Text);
p.CountryCode = ddlCountry.SelectedValue;
p.DisplayName = tbxDisplayName.Text;
p.Save();
yosig81