开发者

Page.Profile not saving after user created in a CreateUserWizard

开发者 https://www.devze.com 2023-01-29 11:07 出处:网络
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.

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 code

public 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号