3

使用向导创建用户。创建用户后,我分配了一个配置文件变量。调用 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" 也是如此。我想不通!

4

0 回答 0