在 CreateUserWizard 中创建用户后,Page.Profile 未保存
我有以下代码,它会触发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您是正确的,调用该方法时用户仍然是匿名的。我对个人资料不熟悉,但我认为您需要通过用户名查找个人资料,而不是依赖当前的个人资料。
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.