Page.Profile not saving after user created in a CreateUserWizard
I Have the following code which fire开发者_如何学运维s OnCreatedUser
and doesn't throw any errors. Profile.Title
is getting set to the correct value when inspected after the assignment.
public void CreateUserForm_CreatedUser(object sender, EventArgs e)
{
var ddlTitle = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Title");
Profile.Title = ddlTitle.SelectedValue;
Profile.Save();
}
However, when I test Profile.Title
on subsequent pages (the user is definitely logged in) it is == ""
;
I'm guessing that this is the users old anonymous profile, not the new profile associated with their newly registered user account.
I've tried adding a Profile_MigrateAnonymous
method (as suggested here) to my Global.asax but this code doesn't get hit.
How do I save title to the new users account profile?
UPDATE
Here's the codepublic void CreateUserForm_CreatedUser(object sender, EventArgs e)
{
var ddlTitle = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Title");
var emailTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
UserProfile profile = (UserProfile)ProfileBase.Create(emailTextBox.Text.Trim());
profile.Title = ddlTitle.SelectedValue;
profile.Save();
}
I think you're correct that the user is still anonymous while that method is called. I'm not familiar with Profile, but I think you need to look the profile up by username instead of relying on the current profile.
精彩评论