在CreateUserWizard中将值存储到Profile中会在aspnet_Users中创建同一用户的2个副本

时间:2012-07-06 00:47:16

标签: c# asp.net profile createuserwizard

使用向导创建用户。创建用户后,我分配一个配置文件变量。调用profile.Save()时,将创建第二个用户。我在web.config中有automaticSaveEnabled =“false”。有趣的是,调试期间不会发生这种情况!

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”也是如此。我无法理解!

0 个答案:

没有答案