Using the wizard to create user. After the user has been created, I assign a profile variable. When profile.Save() is called, a second user is created. I have automaticSaveEnabled="false" in web.config. Interestingly enough, this doesn't happen during debug!
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Int32 li_con_id = 406;
TextBox tbx_username = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
if (tbx_username != null)
{
ls_username = tbx_username.Text;
}
// Store Con ID in user profile:
UserProfile profile = UserProfile.GetUserProfile(ls_username);
profile.con_id = Convert.ToString(li_con_id);
profile.Save();
}
Here's the Profile code:
using System.Web.Profile;
using System.Web.Security;
namespace WebApp
{
public class UserProfile : ProfileBase
{
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
[SettingsAllowAnonymous(false)]
public string Description
{
get { return base["Description"] as string; }
set { base["Description"] = value; }
}
[SettingsAllowAnonymous(false)]
public string Location
{
get { return base["Location"] as string; }
set { base["Location"] = value; }
}
[SettingsAllowAnonymous(false)]
public string con_id
{
get { return base["con_id"] as string; }
set { base["con_id"] = value; }
}
}
}
Web.config
<profile inherits="WebApp.UserProfile" automaticSaveEnabled="false">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" />
</providers>
</profile>
Two users are created: the second is associated with the Profile. Removing profile.Save() causes no profile entry to be created at all, even with automaticSaveEnabled="true". I can't figure it out!