在 CreateUserWizard 中创建用户后,Page.Profile 未保存

发布于 2024-10-07 10:41:29 字数 1172 浏览 4 评论 0原文

我有以下代码,它会触发 OnCreatedUser 并且不会引发任何错误。分配后检查时,Profile.Title 设置为正确的值。

public void CreateUserForm_CreatedUser(object sender, EventArgs e)
{
    var ddlTitle = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Title");
    Profile.Title = ddlTitle.SelectedValue;
    Profile.Save();
}

但是,当我在后续页面上测试 Profile.Title (用户肯定已登录)时,它是 == "";

我猜测这是用户旧的匿名个人资料,而不是与他们新注册的用户帐户关联的新个人资料。

我尝试添加 Profile_MigrateAnonymous 方法(如此处建议)我的 Global.asax 但这段代码没有被命中。

如何将标题保存到新用户帐户配置文件中?

更新
这是代码

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 Have the following code which fires 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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心病无药医 2024-10-14 10:41:29

我认为您是正确的,调用该方法时用户仍然是匿名的。我对个人资料不熟悉,但我认为您需要通过用户名查找个人资料,而不是依赖当前的个人资料。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文