Сохранение значений в Profile в CreateUserWizard создает 2 копии одного и того же пользователя в aspnet_Users.
Использование мастера для создания пользователя. После того, как пользователь был создан, я назначаю переменную профиля. Когда вызывается profile.Save(), создается второй пользователь. У меня есть AutomaticSaveEnabled="false" в web.config. Интересно, что этого не происходит во время отладки!
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();
}
Вот код профиля:
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>
Создаются два пользователя: второй связан с профилем. Удаление profile.Save() приводит к тому, что запись профиля вообще не создается, даже если automaticSaveEnabled="true". Я не могу понять это!